Android Notification Manager问题

时间:2013-08-26 08:53:04

标签: android android-notifications

我的应用程序在收到Log Cat中显示的通知后发生了崩溃,其中NouchMethodError为第107行,即.setWhen(System.currentTimeMillis())。build();在我的文件中,有人可以帮助, 我的设备版本是4.0+,代码如下

        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);

1 个答案:

答案 0 :(得分:0)

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

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