v4支持库通知无效

时间:2013-11-09 07:46:09

标签: android android-notifications android-support-library

我发现了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);

1 个答案:

答案 0 :(得分:1)

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

需要一个小图标。