Skip to content

Commit

Permalink
introduce Android notification channel
Browse files Browse the repository at this point in the history
  • Loading branch information
Julesssss committed Dec 16, 2022
1 parent fde8d11 commit 550756f
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.expensify.chat.customairshipextender;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
Expand All @@ -8,11 +10,13 @@
import android.graphics.Bitmap.Config;
import android.graphics.PorterDuffXfermode;
import android.graphics.PorterDuff.Mode;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.app.Person;
Expand Down Expand Up @@ -48,6 +52,9 @@ public class CustomNotificationProvider extends ReactNotificationProvider {
// Logging
private static final String TAG = "NotificationProvider";

// Define notification channel
public static final String CHANNEL_MESSAGES_ID = "CHANNEL_MESSAGES";
public static final String CHANNEL_MESSAGES_NAME = "Message Notifications";
// Conversation JSON keys
private static final String PAYLOAD_KEY = "payload";
private static final String TYPE_KEY = "type";
Expand All @@ -58,6 +65,9 @@ public class CustomNotificationProvider extends ReactNotificationProvider {

public CustomNotificationProvider(@NonNull Context context, @NonNull AirshipConfigOptions configOptions) {
super(context, configOptions);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createAndRegisterNotificationChannel(context);
}
}

@NonNull
Expand All @@ -82,6 +92,14 @@ protected NotificationCompat.Builder onExtendBuilder(@NonNull Context context, @
return builder;
}

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

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

/**
* Creates a canvas to draw a circle and then draws the bitmap avatar within that circle
* to clip off the area of the bitmap outside the circular path and returns a circular
Expand Down

0 comments on commit 550756f

Please sign in to comment.