0
Androidでアクション可能な通知を開発しています。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で走っている、コンパイルSDK APIが最小SDK私はマシュマロデバイスでテスト20 で、24です。しかし、エミュレータでうまく動作します。リスト内の任意継続的なNotification
存在があるときにボタンは、このようなメディアプレーヤーのコントロールとして、表示されません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();
感謝することができます。私はPriorityとSetwhen(0)も試しました。しかし、変化はありません。 @ rafsanahmad007 – Roster
あなたの通知にスタイルを追加しようとしています: '.setStyle(new NotificationCompat.BigTextStyle()。bigText(th_alert))' – rafsanahmad007
これを参照してください:http://stackoverflow.com/questions/ 13720670/implement-expand-and-collapse-notification-android – rafsanahmad007