ステータスバーに通知する方法。
ステータスバーに通知する必要あったので、メモ。
androidのバージョンによるらしいが、とりあえず
以下サンプルコード
Notification n = new Notification.Builder(this) .setContentTitle("タイトル") .setContentText("通知内容") .setSmallIcon(R.drawable.ic_launcher) //アイコン .setAutoCancel(true) //キャンセルできるように .setOnGoing(true) //継続的に表示させる .build() ; NotificationManager nm = (NotificationManager)getSystemService(Content.NOTIFICATION_SERVICE) ; nm.notify(1, n) ; //nをステータスバーに表示
上記のコードを基礎にいろいろ工夫できる。
以上