diff --git a/app/src/main/java/eu/faircode/email/Widget.java b/app/src/main/java/eu/faircode/email/Widget.java index 8895ece94a..76a4bad8ff 100644 --- a/app/src/main/java/eu/faircode/email/Widget.java +++ b/app/src/main/java/eu/faircode/email/Widget.java @@ -59,7 +59,12 @@ public class Widget extends AppWidgetProvider { static void update(Context context, Integer count) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); - int[] appWidgetIds = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, Widget.class)); + if (appWidgetManager == null) { + Log.w("No app widget manager"); // Fairphone FP2 + return; + } + + int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, Widget.class)); update(context, appWidgetManager, appWidgetIds, count); } diff --git a/app/src/main/java/eu/faircode/email/WidgetUnified.java b/app/src/main/java/eu/faircode/email/WidgetUnified.java index 330e4ad0e5..65d4dd0460 100644 --- a/app/src/main/java/eu/faircode/email/WidgetUnified.java +++ b/app/src/main/java/eu/faircode/email/WidgetUnified.java @@ -40,7 +40,13 @@ public class WidgetUnified extends AppWidgetProvider { static void init(Context context, int appWidgetId) { Log.i("Widget unified init=" + appWidgetId); + AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); + if (appWidgetManager == null) { + Log.w("No app widget manager"); // Fairphone FP2 + return; + } + update(context, appWidgetManager, new int[]{appWidgetId}); } @@ -48,6 +54,11 @@ public class WidgetUnified extends AppWidgetProvider { Log.i("Widget unified update"); if (ActivityBilling.isPro(context)) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); + if (appWidgetManager == null) { + Log.w("No app widget manager"); // Fairphone FP2 + return; + } + int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetUnified.class)); appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.lv); }