v4 support lib Уведомление не работает

я обнаружил странное поведение с библиотекой поддержки 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);

person Sush    schedule 09.11.2013    source источник
comment
Я думаю, вы импортировали правильный .once. Как только вы его проверите...   -  person vinay Maneti    schedule 09.11.2013
comment
Вы можете посмотреть мой ответ здесь: stackoverflow.com/a/16857267/1739882   -  person Chintan Soni    schedule 09.11.2013


Ответы (1)


Документация по адресу http://developer.android.com/guide/topics/ui/notifiers/notifications.html четко указывает, какое содержимое уведомления является обязательным, а какое необязательным.

требуется маленькая иконка.

person Gal Ben-Haim    schedule 09.11.2013