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
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.evollu.react.fcm;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -32,6 +34,7 @@
import java.net.URL;
import java.net.URLDecoder;

import static android.content.Context.NOTIFICATION_SERVICE;
import static com.facebook.react.common.ReactConstants.TAG;

public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
Expand Down Expand Up @@ -78,7 +81,20 @@ protected Void doInBackground(Void... params) {
String subText = bundle.getString("sub_text");
if (subText != null) subText = URLDecoder.decode( subText, "UTF-8" );

NotificationCompat.Builder notification = new NotificationCompat.Builder(mContext, bundle.getString("channel"))
String defaultChannelId = "default";

String channelId = bundle.getString("channel", defaultChannelId);

NotificationManager mngr = (NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE);
if (mngr != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (mngr.getNotificationChannel(channelId) == null) {
channelId = defaultChannelId;
NotificationChannel channel = new NotificationChannel(channelId, "Default", NotificationManager.IMPORTANCE_DEFAULT);
mngr.createNotificationChannel(channel);
}
}

NotificationCompat.Builder notification = new NotificationCompat.Builder(mContext, channelId)
.setContentTitle(title)
.setContentText(body)
.setTicker(ticker)
Expand Down Expand Up @@ -186,7 +202,7 @@ protected Void doInBackground(Void... params) {
}
}
// setBigContentTitle and setSummaryText overrides current title with body and subtext
// that cause to display duplicated body in subtext when picture has specified
// that cause to display duplicated body in subtext when picture has specified
notification.setStyle(bigPicture);
}

Expand Down