Я сталкивался с одним сообщением о переполнении стека с фрагментом кода уведомлений о том, как их следует использовать (с каналом).
Первый раз, когда я использовал код, работала функция входа в приложение при нажатии на уведомление, теперь, когда я добавил некоторые функции, он больше не работает.
Функции, которые я добавил, важны, потому что приложение показывает уведомление, когда игрок начинает играть (информация о названии и действиях воспроизведения / паузы).
Для игрока я использую сервис, поэтому я могу играть в фоновом режиме, и каждое действие может подключаться к игроку.
Для запуска действий при уведомлении я использую ActionReciever с двумя действиями: пауза, возобновление, которые работают правильно.
Я не могу понять, из-за чего перестала работать функция входа в приложение через уведомление.
Есть идеи?
Вот код того, как я создаю уведомление:
public void startNofitication (Context ctx, String title) {
NotificationManager mNotificationManager;
//This is the intent of PendingIntent
Intent intentAction = new Intent(ctx, ActionReceiver.class);
intentAction.putExtra("action", "pause");
intentAction.putExtra("currentTime", getCurrentTime().toString());
PendingIntent pIntentlogin = PendingIntent.getBroadcast(ctx, 1, intentAction, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(ctx, "notify_001");
Intent ii = new Intent(ctx, MediaPlayerService.class);
PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0, ii, 0);
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
bigText.setSummaryText("Hear the music");
mBuilder.setContentIntent(pendingIntent);
mBuilder.setSmallIcon(R.drawable.login_screen);
mBuilder.setPriority(Notification.PRIORITY_MAX);
mBuilder.setStyle(bigText);
mBuilder.addAction(R.drawable.pause2, "Pause", pIntentlogin);
mBuilder.setContentText(title);
mNotificationManager =
(NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
String channelId = "1";
NotificationChannel channel = new NotificationChannel(channelId,
title, NotificationManager.IMPORTANCE_DEFAULT);
mNotificationManager.createNotificationChannel(channel);
mBuilder.setChannelId(channelId);
}
mNotificationManager.notify(0, mBuilder.build());
}