9

私はそれが可能であることを理解しています。少なくとも、さまざまなアプリケーションが通知トレイにアイコンを配置するために使用されていたことがわかります(Skypeなど)。

私のアプリケーションはどうですか?アイコンやメッセージを通知バーに表示するにはどうすればよいですか?

4

3 に答える 3

20

ドキュメンテーション。

オブジェクト内の通知のUI情報とアクションを指定しNotificationCompat.Builderます。通知自体を作成するには、を呼び出します。これは、仕様を含むオブジェクトをNotificationCompat.Builder.build()返します。Notification通知を発行するには、...Notificationを呼び出してオブジェクトをシステムに渡します。NotificationManager.notify()

于 2011-02-16T19:55:26.983 に答える
2

これは、通知メッセージを通知トレイに入れるためのコードです。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); 
于 2015-12-02T11:06:49.197 に答える
0

これは、通知を表示するための優れた例です。

通知デモ

于 2014-04-07T09:41:19.747 に答える