Skip to content

Commit

Permalink
introduce Android notification channel grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
Julesssss committed Dec 16, 2022
1 parent 58932f6 commit fb01fc4
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static androidx.core.app.NotificationCompat.PRIORITY_MAX;

import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.content.Context;
import android.graphics.Bitmap;
Expand Down Expand Up @@ -57,6 +58,9 @@ public class CustomNotificationProvider extends ReactNotificationProvider {
// Define notification channel
public static final String CHANNEL_MESSAGES_ID = "CHANNEL_MESSAGES";
public static final String CHANNEL_MESSAGES_NAME = "Message Notifications";
public static final String CHANNEL_GROUP_ID = "CHANNEL_GROUP_CHATS";
public static final String CHANNEL_GROUP_NAME = "Chats";

// Conversation JSON keys
private static final String PAYLOAD_KEY = "payload";
private static final String TYPE_KEY = "type";
Expand Down Expand Up @@ -103,9 +107,12 @@ protected NotificationCompat.Builder onExtendBuilder(@NonNull Context context, @

@RequiresApi(api = Build.VERSION_CODES.O)
private void createAndRegisterNotificationChannel(@NonNull Context context) {
NotificationChannelGroup channelGroup = new NotificationChannelGroup(CHANNEL_GROUP_ID, CHANNEL_GROUP_NAME);
NotificationChannel channel = new NotificationChannel(CHANNEL_MESSAGES_ID, CHANNEL_MESSAGES_NAME, NotificationManager.IMPORTANCE_HIGH);
channel.setGroup(CHANNEL_GROUP_ID);

NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
notificationManager.createNotificationChannelGroup(channelGroup);
notificationManager.createNotificationChannel(channel);
}

Expand Down

0 comments on commit fb01fc4

Please sign in to comment.