Recreate notification channels on every startup

For better localization support
This commit is contained in:
xynngh 2019-10-18 16:09:46 +04:00
parent 8c32946233
commit f2b5ea712c
2 changed files with 3 additions and 10 deletions

View File

@ -11,6 +11,8 @@ public class App extends Application {
super.onCreate(); super.onCreate();
instance = this; instance = this;
NotificationHelper.createNotificationChannels(this);
} }
public static App getInstance() { public static App getInstance() {

View File

@ -37,8 +37,6 @@ public class NotificationHelper {
private static final String CHANNEL_ID_BLOCKED_INFO = "blocked_info"; private static final String CHANNEL_ID_BLOCKED_INFO = "blocked_info";
public static void showIncomingCallNotification(Context context, NumberInfo numberInfo) { public static void showIncomingCallNotification(Context context, NumberInfo numberInfo) {
createNotificationChannels(context);
Notification notification = createIncomingCallNotification(context, numberInfo); Notification notification = createIncomingCallNotification(context, numberInfo);
String tag = numberInfo.number != null ? NOTIFICATION_TAG_INCOMING_CALL + numberInfo.number : null; 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) { public static void showBlockedCallNotification(Context context, NumberInfo numberInfo) {
createNotificationChannels(context);
Notification notification = createBlockedCallNotification(context, numberInfo); Notification notification = createBlockedCallNotification(context, numberInfo);
String tag = numberInfo.number != null ? NOTIFICATION_TAG_BLOCKED_CALL + numberInfo.number : null; // TODO: handle repeating 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); 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) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager = context.getSystemService(NotificationManager.class); NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
if (notificationManager.getNotificationChannel(CHANNEL_ID_POSITIVE_KNOWN) != null) {
// already created
return;
}
NotificationChannelGroup channelGroupIncoming = new NotificationChannelGroup( NotificationChannelGroup channelGroupIncoming = new NotificationChannelGroup(
CHANNEL_GROUP_ID_INCOMING_CALLS, CHANNEL_GROUP_ID_INCOMING_CALLS,
context.getString(R.string.notification_channel_group_name_incoming_calls)); context.getString(R.string.notification_channel_group_name_incoming_calls));