diff --git a/src/main/java/com/marianhello/bgloc/sync/NotificationHelper.java b/src/main/java/com/marianhello/bgloc/sync/NotificationHelper.java index 9be96879..77e806ae 100644 --- a/src/main/java/com/marianhello/bgloc/sync/NotificationHelper.java +++ b/src/main/java/com/marianhello/bgloc/sync/NotificationHelper.java @@ -85,25 +85,29 @@ public Notification getNotification(String title, String text, String largeIcon, } } - public static void registerAllChannels(Context context) { + public static void registerAllChannels(Context context) { + // Create the NotificationChannel, but only on API 26+ because + // the NotificationChannel class is new and not in the support library if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - String appName = ResourceResolver.newInstance(context).getString(("app_name")); - // Create the NotificationChannel, but only on API 26+ because - // the NotificationChannel class is new and not in the support library + String backgroundServiceChannelName = ResourceResolver.newInstance(context).getString(("background_service_notification_channel_name")); android.app.NotificationManager notificationManager = (android.app.NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - notificationManager.createNotificationChannel(createServiceChannel(appName)); - notificationManager.createNotificationChannel(createSyncChannel()); - notificationManager.createNotificationChannel(createAndroidPermissionsChannel(appName)); + notificationManager.createNotificationChannel(createServiceChannel(backgroundServiceChannelName)); + // comment out these lines as the main app is not using sync service and permissions channel + // TODO: consider dynamically register this notification channel based on config + // notificationManager.createNotificationChannel(createSyncChannel()); + + // String permissionChannelName = ResourceResolver.newInstance(context).getString(("android_permission_notification_channel_name")); + // notificationManager.createNotificationChannel(createAndroidPermissionsChannel(permissionChannelName)); } } public static void registerServiceChannel(Context context) { + // Create the NotificationChannel, but only on API 26+ because + // the NotificationChannel class is new and not in the support library if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - String appName = ResourceResolver.newInstance(context).getString(("app_name")); - // Create the NotificationChannel, but only on API 26+ because - // the NotificationChannel class is new and not in the support library + String backgroundServiceChannelName = ResourceResolver.newInstance(context).getString(("background_service_notification_channel_name")); android.app.NotificationManager notificationManager = (android.app.NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - notificationManager.createNotificationChannel(createServiceChannel(appName)); + notificationManager.createNotificationChannel(createServiceChannel(backgroundServiceChannelName)); } } @@ -120,6 +124,7 @@ public static void registerSyncChannel(Context context) { public static NotificationChannel createServiceChannel(CharSequence name) { NotificationChannel channel = new NotificationChannel(SERVICE_CHANNEL_ID, name, android.app.NotificationManager.IMPORTANCE_LOW); channel.enableVibration(false); + channel.setShowBadge(false); // avoid badge count due to background service notification return channel; } diff --git a/src/main/java/com/marianhello/bgloc/sync/SyncAdapter.java b/src/main/java/com/marianhello/bgloc/sync/SyncAdapter.java index 9c713e98..3dd4c651 100644 --- a/src/main/java/com/marianhello/bgloc/sync/SyncAdapter.java +++ b/src/main/java/com/marianhello/bgloc/sync/SyncAdapter.java @@ -73,7 +73,9 @@ public SyncAdapter( batchManager = new BatchManager(this.getContext()); notificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE); - NotificationHelper.registerSyncChannel(context); + // comment out this line as the main app is not using sync service + // TODO: consider dynamically register this notification channel based on config + // NotificationHelper.registerSyncChannel(context); } /* diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 2b938a08..32a1a4ff 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -1,4 +1,5 @@ app_name + Background location service \ No newline at end of file