Android - невозможно отобразить действия в панели уведомлений

Я разрабатываю Actionable Notifications в Android.

void createActionableNotification() {
    Intent intent = new Intent(this, MainActivity.class);
    PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);

    // Build notification
    // Actions are just fake
    Notification noti = new NotificationCompat.Builder(this)
            .setContentTitle("New mail from " + "[email protected]")
            .setContentText("Subject").setSmallIcon(R.drawable.moneybag)
            .setContentIntent(pIntent)
            .addAction(R.drawable.moneybag, "Call", pIntent)
            .addAction(R.drawable.moneybag, "More", pIntent)
            .addAction(R.drawable.moneybag, "And more", pIntent).build();
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // hide the notification after its selected

    noti.flags |= Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify(0, noti);
}

Таким образом, он отображает действия, подобные этому. Пожалуйста, проверьте изображение ниже. введите здесь описание изображения

Приложение работает с целевым SDK, Compile SDK API — 24, Min SDK — 20. Я тестировал с Marshmallow Device. Но в эмуляторе работает нормально. Версия SDK эмулятора: 24 введите здесь описание изображения


person Roster    schedule 18.01.2017    source источник


Ответы (1)


попробуйте это: работает для API >= 16

 Notification notification = new Notification.Builder(myContext)
.setContentTitle("New mail from " + "[email protected]")
            .setContentText("Subject").setSmallIcon(R.drawable.moneybag)
            .setContentIntent(pIntent)
            .setPriority(Notification.PRIORITY_MAX)
            .addAction(R.drawable.moneybag, "Call", pIntent)
            .addAction(R.drawable.moneybag, "More", pIntent)
            .addAction(R.drawable.moneybag, "And more", pIntent).build();

//The rest of your options
.build();

Кнопки не будут отображаться, если в списке присутствуют текущие Notification, такие как управление медиаплеером, или телефон подключен к ПК через USB, или когда вы редактируете текст...

вы можете попробовать Notification.PRIORITY_MAX обойти это или PRIORITY_HIGH

person rafsanahmad007    schedule 18.01.2017
comment
Спасибо за ответ. Я тоже пробовал Priority и setwhen(0). Но никаких изменений. У меня нет текущих уведомлений на моем телефоне @rafsanahmad007 - person Roster; 18.01.2017
comment
попробуйте добавить стиль в уведомление:.setStyle(new NotificationCompat.BigTextStyle().bigText(th_alert)) - person rafsanahmad007; 18.01.2017
comment
см. это: stackoverflow.com/questions/13720670 / - person rafsanahmad007; 18.01.2017
comment
также попробуйте отключить USB - person rafsanahmad007; 18.01.2017