diff --git a/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java b/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java index 09b39c6e1..c4ff5ad61 100644 --- a/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java +++ b/app/src/main/java/fr/free/nrw/commons/CommonsApplication.java @@ -8,6 +8,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; import android.os.Build; +import android.support.annotation.NonNull; import android.support.annotation.RequiresApi; import com.facebook.drawee.backends.pipeline.Fresco; @@ -122,22 +123,22 @@ public class CommonsApplication extends Application { Stetho.initializeWithDefaults(this); } - - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) { - createNotificationChannel(); - } + createNotificationChannel(this); // Fire progress callbacks for every 3% of uploaded content System.setProperty("in.yuvi.http.fluent.PROGRESS_TRIGGER_THRESHOLD", "3.0"); } - @RequiresApi(26) - private void createNotificationChannel() { - NotificationChannel channel = new NotificationChannel( - NOTIFICATION_CHANNEL_ID_ALL, - getString(R.string.notifications_channel_name_all), NotificationManager.IMPORTANCE_NONE); - NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - manager.createNotificationChannel(channel); + public static void createNotificationChannel(@NonNull Context context) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + NotificationChannel channel = manager.getNotificationChannel(NOTIFICATION_CHANNEL_ID_ALL); + if (channel == null) { + channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID_ALL, + context.getString(R.string.notifications_channel_name_all), NotificationManager.IMPORTANCE_DEFAULT); + manager.createNotificationChannel(channel); + } + } } /** diff --git a/app/src/main/java/fr/free/nrw/commons/upload/UploadService.java b/app/src/main/java/fr/free/nrw/commons/upload/UploadService.java index c2fdfbe8d..a5b8da456 100644 --- a/app/src/main/java/fr/free/nrw/commons/upload/UploadService.java +++ b/app/src/main/java/fr/free/nrw/commons/upload/UploadService.java @@ -121,7 +121,7 @@ public class UploadService extends HandlerService { @Override public void onCreate() { super.onCreate(); - + CommonsApplication.createNotificationChannel(getApplicationContext()); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); }