首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android Notification Manager问题

Android Notification Manager问题
EN

Stack Overflow用户
提问于 2013-08-26 16:53:04
回答 1查看 365关注 0票数 0

我的应用程序收到通知后崩溃,它显示在日志猫第107行的NosuchMethodError,即.setWhen(System.currentTimeMillis()).build();在我的文件中,有人能帮助我吗,我的设备版本是4.0+,代码如下

代码语言:javascript
复制
        final Bundle bundle = intent.getExtras();
    final Object systemService = context.getSystemService(Context.NOTIFICATION_SERVICE);

    // Retrieve notification details from the intent
    final String tickerText = bundle.getString(TICKER_TEXT);
    final String message = bundle.getString(MESSAGE);
    final String notificationTitle = bundle.getString(TITLE);
    final String notificationSubText = bundle.getString(SUBTITLE);
    int notificationId = 0;
    Intent pintent = new Intent(context,MainActivity.class);
    final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, pintent, 0);

    Notification notification = new Notification.Builder(context)
                                .setContentTitle(notificationTitle)
                                .setContentText(message)
                                .setTicker(tickerText)
                                .setAutoCancel(true)
                                .setSound(Uri.parse("android.resource://"+ context.getPackageName() + "/raw/horn"))
                                .setSmallIcon(R.drawable.ic_launcher)
                                .setContentIntent(contentIntent)
                                .setWhen(System.currentTimeMillis()).build();

    NotificationManager notificationMgr = (NotificationManager) systemService;
    notificationMgr.notify(notificationId, notification);
EN

回答 1

Stack Overflow用户

发布于 2013-08-26 16:55:35

可能是因为setWhen()是在API 11中添加的,请检查您是否在任何较低版本的设备上运行该项目。

如果是这种情况,那么你必须向后兼容,并尝试了解它。

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

https://stackoverflow.com/questions/18440223

复制
相关文章

相似问题

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