私はそれが可能であることを理解しています。少なくとも、さまざまなアプリケーションが通知トレイにアイコンを配置するために使用されていたことがわかります(Skypeなど)。
私のアプリケーションはどうですか?アイコンやメッセージを通知バーに表示するにはどうすればよいですか?
私はそれが可能であることを理解しています。少なくとも、さまざまなアプリケーションが通知トレイにアイコンを配置するために使用されていたことがわかります(Skypeなど)。
私のアプリケーションはどうですか?アイコンやメッセージを通知バーに表示するにはどうすればよいですか?
オブジェクト内の通知のUI情報とアクションを指定し
NotificationCompat.Builder
ます。通知自体を作成するには、を呼び出します。これは、仕様を含むオブジェクトをNotificationCompat.Builder.build()
返します。Notification
通知を発行するには、...Notification
を呼び出してオブジェクトをシステムに渡します。NotificationManager.notify()
これは、通知メッセージを通知トレイに入れるためのコードです。100%機能しています。
NotificationManager notificationManager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
Intent intent = new Intent(this, EndActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
// build notification
// the addAction re-use the same intent to keep the example short
Notification n = new Notification.Builder(this)
.setContentTitle("My message")
.setContentText("Subject")
.setSmallIcon(R.drawable.MyApplogo)
.setContentIntent(pIntent)
.setAutoCancel(true)
.setStyle(new Notification.BigTextStyle().bigText(""+msg.get(3))).build();
// .addAction(R.drawable.line, "", pIntent).build();
n.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, n);
これは、通知を表示するための優れた例です。