首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NotificationManager.notify抛出IllegalArgumentException

NotificationManager.notify抛出IllegalArgumentException
EN

Stack Overflow用户
提问于 2012-11-23 04:40:04
回答 1查看 1.1K关注 0票数 0

我有一个成功创建NotificationNotificationManager

代码语言:javascript
复制
 private void showNotification() {
    Notification notification = new Notification(R.drawable.snog_icon, getString(R.string.sn_g_entering_beacon_mode_),
            System.currentTimeMillis());

    // The PendingIntent to launch our activity if the user selects this notification
    Intent i = new Intent(this, SnogActivity.class);
    i.putExtra("fromNotification", "yes");

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);

    notification.setLatestEventInfo(this, getString(R.string.sn_g_avalanche_buddy),
                   getString(R.string.beacon_mode_activated_), contentIntent);
    notification.flags |= Notification.FLAG_ONGOING_EVENT; // Notification.DEFAULT_ALL 

    // Send the notification.
    // We use a string id because it is a unique number.  We use it later to cancel.
    mNM.notify(R.string.service_started, notification);
}

这部分工作正常,它会显示我的通知,当我点击通知时,正确的活动就会启动。稍后在应用程序中,我尝试通知一个简单的通知:

代码语言:javascript
复制
Notification not = new Notification(R.drawable.snog_icon, "checker", System.currentTimeMillis());
not.flags |= Notification.DEFAULT_ALL;

mNM.notify(R.string.checker, not);

这会使应用程序在带有IllegalArgumentExceptionnotify()调用中崩溃。根据相当多的互联网结果,我应该使用NotificationCompat.Builder,但这甚至是不可用的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-23 04:50:33

您可以修复此异常,但我宁愿从一开始就使用NotifcationCompat。它可以在兼容性包中找到,您必须右键单击您的eclipse项目> Android Tools > add Support Library添加

之后,您将在project...then中获得可用的NotificationCompat。请访问站点:http://developer.android.com/guide/topics/ui/notifiers/notifications.html

这里有一些很好的简单的例子。

祝好运!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13519695

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档