A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
mobile: migrated off the deprecated background-activity-launch mode
Ammar Ahmed0939f0f8059c
diff --git a/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/NotePreviewWidget.java b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/NotePreviewWidget.javaindex 831eaaa87..111a4b23a 100644--- a/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/NotePreviewWidget.java+++ b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/NotePreviewWidget.java@@ -1,6 +1,5 @@package com.streetwriters.notesnook;-import android.app.ActivityOptions;import android.app.PendingIntent;import android.appwidget.AppWidgetManager;import android.appwidget.AppWidgetProvider;@@ -8,7 +7,6 @@ import android.content.Context;import android.content.Intent;import android.content.SharedPreferences;import android.net.Uri;-import android.os.Build;import android.os.Bundle;import android.widget.RemoteViews;import com.google.gson.Gson;@@ -34,7 +32,7 @@ public class NotePreviewWidget extends AppWidgetProvider {intent.setAction(Intent.ACTION_VIEW);intent.putExtra(RCTNNativeModule.IntentType, "OpenNote");intent.setData(Uri.parse("nn://note/" + note.getId()));- PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE, getActivityOptionsBundle());+ PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE, WidgetUtils.getActivityOptionsBundle());views.setOnClickPendingIntent(R.id.open_note, pendingIntent);appWidgetManager.updateAppWidget(appWidgetId, views);@@ -45,16 +43,6 @@ public class NotePreviewWidget extends AppWidgetProvider {super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions);}- private static Bundle getActivityOptionsBundle() {- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {- ActivityOptions activityOptions = ActivityOptions.makeBasic();- activityOptions.setPendingIntentCreatorBackgroundActivityStartMode(- ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED);- return activityOptions.toBundle();- } else- return null;- }-@Overridepublic void onDeleted(Context context, int[] appWidgetIds) {super.onDeleted(context, appWidgetIds);diff --git a/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/NoteWidget.java b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/NoteWidget.javaindex 6207f5ef1..6efe9ed1e 100644--- a/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/NoteWidget.java+++ b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/NoteWidget.java@@ -1,12 +1,10 @@package com.streetwriters.notesnook;-import android.app.ActivityOptions;import android.app.PendingIntent;import android.appwidget.AppWidgetManager;import android.appwidget.AppWidgetProvider;import android.content.Context;import android.content.Intent;-import android.os.Build;import android.os.Bundle;import android.widget.RemoteViews;@@ -24,20 +22,10 @@ public class NoteWidget extends AppWidgetProvider {static void setClickIntent(Context context, RemoteViews views) {Intent intent = new Intent(context, ShareActivity.class);- PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE, getActivityOptionsBundle());+ PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE, WidgetUtils.getActivityOptionsBundle());views.setOnClickPendingIntent(R.id.new_note, pendingIntent);}- private static Bundle getActivityOptionsBundle() {- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {- ActivityOptions activityOptions = ActivityOptions.makeBasic();- activityOptions.setPendingIntentCreatorBackgroundActivityStartMode(- ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED);- return activityOptions.toBundle();- } else- return null;- }-@Overridepublic void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) {super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions);diff --git a/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/ReminderWidgetProvider.java b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/ReminderWidgetProvider.javaindex 3ecd4daed..ec62755ca 100644--- a/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/ReminderWidgetProvider.java+++ b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/ReminderWidgetProvider.java@@ -1,14 +1,11 @@package com.streetwriters.notesnook;-import android.app.ActivityOptions;import android.app.PendingIntent;import android.appwidget.AppWidgetManager;import android.appwidget.AppWidgetProvider;import android.content.Context;import android.content.Intent;import android.net.Uri;-import android.os.Build;-import android.os.Bundle;import android.widget.RemoteViews;public class ReminderWidgetProvider extends AppWidgetProvider {@@ -23,20 +20,10 @@ public class ReminderWidgetProvider extends AppWidgetProvider {}- private static Bundle getActivityOptionsBundle() {- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {- ActivityOptions activityOptions = ActivityOptions.makeBasic();- activityOptions.setPendingIntentCreatorBackgroundActivityStartMode(- ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED);- return activityOptions.toBundle();- } else- return null;- }-static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, RemoteViews views) {Intent listview_intent_template = new Intent(context, MainActivity.class);listview_intent_template.setAction(Intent.ACTION_VIEW);- PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, listview_intent_template, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE, getActivityOptionsBundle());+ PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, listview_intent_template, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE, WidgetUtils.getActivityOptionsBundle());views.setPendingIntentTemplate(R.id.widget_list_view, pendingIntent);Intent new_reminder_intent = new Intent(context, MainActivity.class);@@ -44,7 +31,7 @@ public class ReminderWidgetProvider extends AppWidgetProvider {new_reminder_intent.setAction(Intent.ACTION_VIEW);new_reminder_intent.putExtra(RCTNNativeModule.IntentType, "NewReminder");new_reminder_intent.setData(Uri.parse("https://app.notesnook.com/new_reminder"));- PendingIntent pendingIntent2 = PendingIntent.getActivity(context, appWidgetId, new_reminder_intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE, getActivityOptionsBundle());+ PendingIntent pendingIntent2 = PendingIntent.getActivity(context, appWidgetId, new_reminder_intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE, WidgetUtils.getActivityOptionsBundle());views.setOnClickPendingIntent(R.id.add_button, pendingIntent2);Intent list_remote_adapter_intent = new Intent(context, ReminderViewsService.class);diff --git a/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/WidgetUtils.java b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/WidgetUtils.javanew file mode 100644index 000000000..0d6b5c7a8--- /dev/null+++ b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/WidgetUtils.java@@ -0,0 +1,36 @@+package com.streetwriters.notesnook;++import android.app.ActivityOptions;+import android.os.Build;+import android.os.Bundle;++/**+ * Shared helpers for the home screen widgets.+ */+public class WidgetUtils {++ /**+ * Options attached to the PendingIntents our widgets hand to the launcher, opting the creator+ * (us) in to background activity starts so a tap on the widget can bring up an activity.+ *+ * MODE_BACKGROUND_ACTIVITY_START_ALLOWED is deprecated since API 36 and Android 17 extends the+ * background activity launch restrictions to IntentSender, so on API 36+ we use the narrower+ * MODE_BACKGROUND_ACTIVITY_START_ALLOW_IF_VISIBLE instead. That is enough for widgets: the+ * sender is the launcher, which is visible whenever the user taps the widget.+ */+ static Bundle getActivityOptionsBundle() {+ ActivityOptions activityOptions;+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA) {+ activityOptions = ActivityOptions.makeBasic();+ activityOptions.setPendingIntentCreatorBackgroundActivityStartMode(+ ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOW_IF_VISIBLE);+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {+ activityOptions = ActivityOptions.makeBasic();+ activityOptions.setPendingIntentCreatorBackgroundActivityStartMode(+ ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED);+ } else {+ return null;+ }+ return activityOptions.toBundle();+ }+}