Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/android/GcmReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import android.app.Notification;
import android.app.NotificationManager;
import android.app.NotificationChannel;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
Expand Down Expand Up @@ -66,6 +68,10 @@ public void createNotification(Context context, Bundle extras)
String channel = extras.getString("C");
String message = extras.getString("message");

String CHANNEL_ID = "cp_channel_01"; //The id of the channel.
CharSequence name = "Notifications"; // The user-visible name of the channel.
int importance = NotificationManager.IMPORTANCE_HIGH;

int largeIcon = getIcon(context, "large_notification_icon");

Bitmap appIcon = BitmapFactory.decodeResource(context.getResources(), largeIcon);
Expand All @@ -74,7 +80,7 @@ public void createNotification(Context context, Bundle extras)

int smallIcon = getIcon(context, "small_notification_icon");
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
new NotificationCompat.Builder(context, CHANNEL_ID)
.setDefaults(defaults)
.setPriority(getAppPriority(context))
.setLargeIcon(appIcon)
Expand Down Expand Up @@ -107,6 +113,11 @@ public void createNotification(Context context, Bundle extras)
Log.e(TAG, "Number format exception - Error parsing Notification ID" + e.getMessage());
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
mNotificationManager.createNotificationChannel(mChannel);
}

mNotificationManager.notify(appName, notId, mBuilder.build());
}

Expand Down