Это метод, который я использую для локальных уведомлений со дня 1
private void sendNotification(Blog blog) {
String title=blog.getTitle();
String desc=blog.getDesc();
String img=blog.getImage();
String time =blog.getTimestamp();
Bundle bundle = new Bundle();
bundle.putString("title", title);
bundle.putString("desc", desc);
bundle.putString("image", img);
bundle.putString("time", time);
Intent intent = new Intent(this, NavigationActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("blog", bundle);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), NOTIFICATION_TAG,
intent, PendingIntent.FLAG_ONE_SHOT);
String channelId = getString(R.string.default_notification_channel_id);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
URL url = new URL(img);
Notification notification = new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.logo_icon)
.setContentTitle(title)
.setContentText(desc)
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(BitmapFactory.decodeStream((InputStream)url.getContent()))
.bigLargeIcon(null))
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Since android Oreo notification channel is needed.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId,
"OlaitexBlog notifications",
NotificationManager.IMPORTANCE_DEFAULT);
Objects.requireNonNull(notificationManager).createNotificationChannel(channel);
}
Objects.requireNonNull(notificationManager).notify(0 /* ID of notification */, notification );
}catch (Exception e){
e.printStackTrace();
}
}
Спросите меня, что вы здесь не понимаете