Это моя функция buildNotification
notificationView = new RemoteViews(getPackageName(), R.layout.notification_layout);
//this is the intent that is supposed to be called when the button is clicked
///////////////TOGGLE/////////////////
Intent toggleIntent = new Intent("com.hbs.andMovie.notification.TOGGLE");
PendingIntent pendingToggleIntent = PendingIntent.getBroadcast(this, 0, toggleIntent, 0);
notificationView.setOnClickPendingIntent(R.id.noti_play, pendingToggleIntent);
///////////////PLAY NEXT//////////////
Intent ffIntent = new Intent("com.hbs.andMovie.notification.FF");
PendingIntent pendingFfIntent = PendingIntent.getBroadcast(this, 0, ffIntent, 0);
notificationView.setOnClickPendingIntent(R.id.noti_ff, pendingFfIntent);
///////////////PLAY PREV//////////////
Intent rewIntent = new Intent("com.hbs.andMovie.notification.REW");
PendingIntent pendingRewIntent = PendingIntent.getBroadcast(this, 0, rewIntent, 0);
notificationView.setOnClickPendingIntent(R.id.noti_rew, pendingRewIntent);
///////////////CLOSE//////////////////
Intent closeIntent = new Intent("com.hbs.andMovie.notification.CLOSE");
PendingIntent pendingCloseIntent = PendingIntent.getBroadcast(this, 0, closeIntent, 0);
notificationView.setOnClickPendingIntent(R.id.noti_close, pendingCloseIntent);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String NOTIFICATION_CHANNEL_ID = "com.hbs.andmovie";
String channelName = "DX_Player_Service";
NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_HIGH);
chan.setLightColor(Color.BLUE);
chan.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
assert manager != null;
manager.createNotificationChannel(chan);
notification = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setOngoing(true)
.setSmallIcon(R.drawable.ic_notification)
.setContent(notificationView)
.setWhen(System.currentTimeMillis())
.setCategory(Notification.CATEGORY_SERVICE)
.build();
} else {
notification = new Notification.Builder(AMPlayerCore.this)
.setContent(notificationView)
.setSmallIcon(R.drawable.ic_notification)
.setWhen(System.currentTimeMillis())
.setPriority(Notification.PRIORITY_HIGH)
.build();
}
notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
notification.visibility = Notification.VISIBILITY_PUBLIC;
//the intent that is started when the notification is clicked
Intent notificationIntent = new Intent(this, AMPlayerUI.class);
notificationIntent.setData(uri);
notificationIntent.putExtra(getString(R.string._mode), AMPlayerUI.mode);
notification.contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
startForeground(1, notification);
Также у меня есть AsyncTask для обновления содержимого удаленного просмотра каждые 5 секунд.
notificationView.setTextViewText(R.id.noti_title, title);
notificationView.setImageViewResource(R.id.noti_thumb, R.drawable.film_strip);
notificationManager.notify(1, notification);
Проблема в том, что нажатия кнопок не работают на устройствах под управлением Oreo и выше ??
На старых устройствах работает нормально ..