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

Here is a great example to display the notification.

Notification Demo

于 2014-04-07T09:41:19.747 回答