Skip to content

Commit

Permalink
Merge pull request #128 from iugo-robert/android_targetSdkVersion_26
Browse files Browse the repository at this point in the history
As of Android 26 a Notification channel is required for push notifications to work correctly
  • Loading branch information
taivo authored Nov 29, 2018
2 parents 6d4575f + 7810870 commit bacb4eb
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/android/ParsePushPluginReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
public class ParsePushPluginReceiver extends ParsePushBroadcastReceiver {
public static final String LOGTAG = "ParsePushPluginReceiver";
public static final String RESOURCE_PUSH_ICON_COLOR = "parse_push_icon_color";
private static final String DEFAULT_CHANNEL_ID = "parse_push";
private static final String DEFAULT_CHANNEL_TITLE = "Default Channel";

private static JSONObject MSG_COUNTS = new JSONObject();
private static int badgeCount = 0;
Expand Down Expand Up @@ -188,7 +190,18 @@ protected Notification getNotification(Context context, Intent intent) {
PendingIntent deleteIntent = PendingIntent.getBroadcast(context, deleteIntentRequestCode, dIntent,
PendingIntent.FLAG_UPDATE_CURRENT);

NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationManager notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel mChannel = notifManager.getNotificationChannel(DEFAULT_CHANNEL_ID);

if (mChannel == null) {
mChannel = new NotificationChannel(DEFAULT_CHANNEL_ID, DEFAULT_CHANNEL_TITLE, importance);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
notifManager.createNotificationChannel(mChannel);
}

NotificationCompat.Builder builder = new NotificationCompat.Builder(context, DEFAULT_CHANNEL_ID);

// check if this is a silent notification
boolean isSilent = !pnData.has("title") && !pnData.has("alert");
Expand Down

0 comments on commit bacb4eb

Please sign in to comment.