Android v4支持库通知不工作

Android v4支持库通知不工作,android,android-notifications,android-support-library,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.getAc

我发现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);
位于的文档明确说明了哪些通知内容是必需的,哪些是可选的


需要一个小图标。

我认为您导入了正确的图标。一旦您检查它,您可以在此处查看我的答案: