Вам необходимо проверить версию.Если версия> = Oreo, вам нужно добавить идентификатор канала.Пожалуйста, посмотрите пример кода ниже, который работает для меня:
public void createNotification(Bitmap bitmap, String aMessage, Context context, int icon, String titles, String noti_id, String mid, String att_url, String mname) {
NotificationManager notifManager = null;
final int NOTIFY_ID = 0; // ID of notification
String id = context.getString(R.string.default_notification_channel_id); // default_channel_id
// String title = context.getString(R.string.default_notification_channel_id); // Default Channel
String title = titles;
Intent intent;
PendingIntent pendingIntent;
NotificationCompat.Builder builder;
NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
bigPictureStyle.setBigContentTitle(title);
String msg = aMessage;
// bigPictureStyle.setSummaryText("Summary text appears on expanding the notification");
bigPictureStyle.setSummaryText(msg);
bigPictureStyle.bigPicture(bitmap);
if (notifManager == null) {
notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
}
String m_namse = "Marwadi University - " + mname;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = notifManager.getNotificationChannel(id);
if (mChannel == null) {
mChannel = new NotificationChannel(id, title, importance);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
notifManager.createNotificationChannel(mChannel);
}
builder = new NotificationCompat.Builder(context, id);
intent = new Intent(context, FullScreenActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
// List<String> test = new ArrayList<String>();
// test.add();
intent.putExtra("title", titles);
intent.putExtra("body", aMessage);
ConstantData.setNotificaitonId(context);
// ConstantData.getNotificaitonId(context);
bundle.putString("values", str);
intent.putExtra("img_path", imageUri);
intent.putExtra("n_id", noti_id);
intent.putExtras(bundle);
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
builder.setContentTitle(aMessage) // required
.setSmallIcon(R.drawable.mu_top_white) // required
.setContentText(m_namse) // required
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setStyle(bigPictureStyle)
.setContentIntent(pendingIntent)
.setTicker(aMessage)
.setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
.setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
} else {
builder = new NotificationCompat.Builder(context, id);
// intent = new Intent(context, AllNotificationActivity.class);
intent = new Intent(context, FullScreenActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("title", titles);
intent.putExtra("body", aMessage);
// intent.putExtra("img_path", imageUri);
intent.putExtra("img_path", imageUri);
intent.putExtra("n_id", noti_id);
intent.putExtra("mid", mid);
ConstantData.setNotificaitonId(context);
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
builder.setContentTitle(aMessage) // required
.setSmallIcon(R.drawable.mu_top_white) // required
.setContentText(m_namse) // required
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setStyle(bigPictureStyle)
.setContentIntent(pendingIntent)
.setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
.setTicker(aMessage)
.setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400})
.setPriority(Notification.PRIORITY_HIGH);
}
Notification notification = builder.build();
notifManager.notify(NOTIFY_ID, notification);
}
And then Simple call this method:
createNotification(bitmap, message, mContext, R.drawable.main_logo, title, noti_id, mid, att_url, msg);