Я делаю приложение для Android и хочу, чтобы мое приложение было настроено на notifications_fragment
при нажатии на уведомление. Но я не знаю, как это сделать. Я использую этот код:
private void getNotification(String notificationTitle, String notificationBody, String clickAction) {
Intent intent = new Intent(clickAction);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("title", notificationTitle);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String NOTIFICATION_CHANNEL_ID = "my_channel_id_01";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "My Notifications", NotificationManager.IMPORTANCE_HIGH);
notificationChannel.setDescription(notificationTitle);
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
notificationChannel.enableVibration(true);
notificationManager.createNotificationChannel(notificationChannel);
}
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notificationBuilder.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.mini_icon)
.setLargeIcon(BitmapFactory.decodeResource(getApplication().getResources(), R.drawable.clustore_logo_108dp))
.setTicker("From: Clustore")
.setContentTitle(notificationTitle)
.setContentText(notificationBody)
.setContentInfo("Clustore")
.setContentIntent(pendingIntent)
.setSound(defaultSoundUri);
notificationManager.notify(0, notificationBuilder.build());
}