Android NotificationCompat.BuilderのaddActionで指定したボタンが消える
AndroidのSDKのバージョンが16以上から、Notificationにボタンなどを表示して、Notificationエリアからアプリのいろんなことができるようになりました。
試してみていると、時々出るときと出ないときが・・・?
調べてみると、なんと他の通知が出ているとき、そして他の通知が上位に表示されているときは、ボタンが出ないらしい・・・
下記のサイトさんで紹介されてました、ありがとうございます!!
http://stackoverflow.com/questions/18249871/android-notification-buttons-not-showing-up
ってか、ホント、それ早く言ってよ…って感じですね。
setPriority(Notification.PRIORITY_MAX)
とやれば、一番上に通知を持ってこれるので、とりあえずの解決になります!!
NotificationCompat.Builder b = new NotificationCompat.Builder(this);
b.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_launcher)
.setTicker("テスト")
.setContentTitle("テストタイトル")
.setContentText("テストだってばよ!!")
.setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND)
.setContentIntent(contentIntent)
.addAction(R.drawable.close_cross, "キャンセル",
contentIntent)
.setPriority(Notification.PRIORITY_MAX)
.setContentInfo("Info");
NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, b.build());
