-2

我发现 android 支持库 v4 有一个奇怪的行为。仅当我们为通知设置设置小图标时,通知才会起作用,否则不会在状态栏上发布任何通知。示例代码是代码发布在下面请看。谁能解释为什么这种奇怪的行为。

 // below code will not post any notification 

 Intent intent = new Intent(context, MainActivity.class);
 PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);
 Notification n  = new Builder(context.getApplicationContext())
                 .setContentTitle("simple notification title")
                 .setContentText("simple message")
                 .setContentIntent(pendingIntent)
                .setAutoCancel(true)
                .addAction(R.drawable.ic_launcher, "Call", pIntent)
                .addAction(R.drawable.ic_launcher, "More", pIntent)
                .addAction(R.drawable.ic_launcher, "And more",pIntent).build();
 NotificationManager notificationManager =(NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
                                          notificationManager.notify(0, n);

// 下面的代码将发布通知

 Intent intent = new Intent(context, MainActivity.class);
 PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);
 Notification n  = new Builder(context.getApplicationContext())
                .setContentTitle("simple notification title")
                .setContentText("simple message")
                .setContentIntent(pendingIntent)
                .setAutoCancel(true)
          //this below one line piece of code is making difference 
                .setSmallIcon(R.drawable.ic_launcher)
                .addAction(R.drawable.ic_launcher, "Call", pIntent)
                .addAction(R.drawable.ic_launcher, "More", pIntent)
                .addAction(R.drawable.ic_launcher, "And more",pIntent).build();


 NotificationManager notificationManager =(NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
                                          notificationManager.notify(0, n);
4

1 回答 1

1

http://developer.android.com/guide/topics/ui/notifiers/notifications.html上的文档清楚地说明了哪些通知内容是必需的,哪些是可选的。

需要一个小图标。

于 2013-11-09T08:00:44.833 回答