Android 通知不';在姜汁面包中不起作用,但在果冻豆中起作用

Android 通知不';在姜汁面包中不起作用,但在果冻豆中起作用,android,android-notifications,Android,Android Notifications,我正在尝试显示通知,但它在果冻豆和姜饼中都非常有效。没有错误/问题。我只想在单击后取消通知 最低Api级别为10。 这是代码 NotificationManager notifyManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder notification = new Notif

我正在尝试显示
通知
,但它在
果冻豆
姜饼
中都非常有效。没有错误/问题。我只想在单击后取消
通知

最低Api级别为10。

这是代码

    NotificationManager notifyManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder notification = new NotificationCompat.Builder(
            context);

    notification.setSmallIcon(R.drawable.ic_launcher);
    notification.setContentTitle("Alarm");
    notification.setContentText("Wake up!!");

    notification.setVibrate(new long[] { 500 });
    notification.setWhen(System.currentTimeMillis());
    notification.setAutoCancel(true);

    Notification notif = notification.build();

    notifyManager.notify(1, notif);

如果有任何帮助,我们将不胜感激。

我进行了API级别检查,并对除Jelly Bean之外的任何内容执行了一些不同的操作:

if(jellybeanOrHigher()) { ///Jelly bean } else { NotificationCompat2.Builder mBuilder = new NotificationCompat2.Builder(this.context) ........ } if(jellybeanOrHigher()) { ///果冻豆 } 其他的 { NotificationCompat2.Builder mBuilder=新的NotificationCompat2.Builder(this.context) ........ }
这也许能帮你解决问题。我花了很长时间才设置好通知,所以这对我来说很有效

我进行了API级别检查,并对除Jelly Bean之外的任何东西做了一些不同的操作:

if(jellybeanOrHigher()) { ///Jelly bean } else { NotificationCompat2.Builder mBuilder = new NotificationCompat2.Builder(this.context) ........ } if(jellybeanOrHigher()) { ///果冻豆 } 其他的 { NotificationCompat2.Builder mBuilder=新的NotificationCompat2.Builder(this.context) ........ }
这也许能帮你解决问题。我花了很长时间才设置好通知,所以这对我来说很有效

您是通过服务运行此功能的吗?我运行的是
BroadcastReceiver
很惊讶它没有崩溃。我尝试了你的代码,但它确实失败了,出现了堆栈跟踪。你需要提供一个悬挂式帐篷——这就是它在以前版本上的工作方式。PendingEvent不一定是一个活动,它可能指向一个空广播。您是从服务运行此功能的吗?我正在运行
BroadcastReceiver
令人惊讶的是,它当时没有崩溃。我尝试了你的代码,但它确实失败了,出现了堆栈跟踪。你需要提供一个悬挂式帐篷——这就是它在以前版本上的工作方式。悬而未决的内容不一定是一个活动,它可能指向一个空广播。我不想启动任何活动不,那只是我的代码片段,只需使用NotificationCompat2.Builder我不想启动任何活动不,那只是我的代码片段,只需使用NotificationCompat2.Builder