From f2b5ea712c92e40c0387ba25f84189e75c0b4e1d Mon Sep 17 00:00:00 2001 From: xynngh Date: Fri, 18 Oct 2019 16:09:46 +0400 Subject: [PATCH] Recreate notification channels on every startup For better localization support --- .../java/dummydomain/yetanothercallblocker/App.java | 2 ++ .../yetanothercallblocker/NotificationHelper.java | 11 +---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/App.java b/app/src/main/java/dummydomain/yetanothercallblocker/App.java index fdbab5b..1e77ecd 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/App.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/App.java @@ -11,6 +11,8 @@ public class App extends Application { super.onCreate(); instance = this; + + NotificationHelper.createNotificationChannels(this); } public static App getInstance() { diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/NotificationHelper.java b/app/src/main/java/dummydomain/yetanothercallblocker/NotificationHelper.java index 1803dc2..36508c0 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/NotificationHelper.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/NotificationHelper.java @@ -37,8 +37,6 @@ public class NotificationHelper { private static final String CHANNEL_ID_BLOCKED_INFO = "blocked_info"; public static void showIncomingCallNotification(Context context, NumberInfo numberInfo) { - createNotificationChannels(context); - Notification notification = createIncomingCallNotification(context, numberInfo); String tag = numberInfo.number != null ? NOTIFICATION_TAG_INCOMING_CALL + numberInfo.number : null; @@ -51,8 +49,6 @@ public class NotificationHelper { } public static void showBlockedCallNotification(Context context, NumberInfo numberInfo) { - createNotificationChannels(context); - Notification notification = createBlockedCallNotification(context, numberInfo); String tag = numberInfo.number != null ? NOTIFICATION_TAG_BLOCKED_CALL + numberInfo.number : null; // TODO: handle repeating @@ -161,15 +157,10 @@ public class NotificationHelper { return PendingIntent.getActivity(context, 0, intent, 0); } - private static void createNotificationChannels(Context context) { + static void createNotificationChannels(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager notificationManager = context.getSystemService(NotificationManager.class); - if (notificationManager.getNotificationChannel(CHANNEL_ID_POSITIVE_KNOWN) != null) { - // already created - return; - } - NotificationChannelGroup channelGroupIncoming = new NotificationChannelGroup( CHANNEL_GROUP_ID_INCOMING_CALLS, context.getString(R.string.notification_channel_group_name_incoming_calls));