diff --git a/app/src/main/java/app/fedilab/android/services/LiveNotificationDelayedService.java b/app/src/main/java/app/fedilab/android/services/LiveNotificationDelayedService.java index d8a402a6c..af017d60a 100644 --- a/app/src/main/java/app/fedilab/android/services/LiveNotificationDelayedService.java +++ b/app/src/main/java/app/fedilab/android/services/LiveNotificationDelayedService.java @@ -89,10 +89,7 @@ public class LiveNotificationDelayedService extends Service { super.onCreate(); final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true); - if( !notify ){ - stopSelf(); - return; - } + if (Build.VERSION.SDK_INT >= 26) { channel = new NotificationChannel(CHANNEL_ID, "Live notifications", @@ -100,6 +97,7 @@ public class LiveNotificationDelayedService extends Service { ((NotificationManager) Objects.requireNonNull(getSystemService(Context.NOTIFICATION_SERVICE))).createNotificationChannel(channel); } + SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); List accountStreams = new AccountDAO(getApplicationContext(), db).getAllAccountCrossAction(); totalAccount = 0; @@ -128,6 +126,10 @@ public class LiveNotificationDelayedService extends Service { .setContentText(getString(R.string.top_notification_message, String.valueOf(totalAccount), String.valueOf(eventsCount))).build(); startForeground(1, notification); + if( !notify ){ + stopSelf(); + return; + } if (totalAccount > 0) { startStream(); } else { diff --git a/app/src/main/java/app/fedilab/android/services/LiveNotificationService.java b/app/src/main/java/app/fedilab/android/services/LiveNotificationService.java index 3188c8af6..15e7946bf 100644 --- a/app/src/main/java/app/fedilab/android/services/LiveNotificationService.java +++ b/app/src/main/java/app/fedilab/android/services/LiveNotificationService.java @@ -105,10 +105,6 @@ public class LiveNotificationService extends Service implements NetworkStateRece super.onCreate(); final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true); - if( !notify ){ - stopSelf(); - return; - } networkStateReceiver = new NetworkStateReceiver(); networkStateReceiver.addListener(this); registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION)); @@ -147,6 +143,10 @@ public class LiveNotificationService extends Service implements NetworkStateRece .setContentText(getString(R.string.top_notification_message, String.valueOf(totalAccount), String.valueOf(eventsCount))).build(); startForeground(1, notification); + if( !notify ){ + stopSelf(); + return; + } if (totalAccount == 0) { stopSelf(); }