Notification doesn't show in Ginger Bread but works in JellyBean

十年热恋 提交于 2019-12-11 09:06:27

问题


I am trying to show notification but it works perfectly in Jelly Bean and in Ginger Bread it doesn't work. No errors/issue. I just want to cancel the notification once its clicked.

Minimum Api level is 10.

Here is the code.

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

Any Help would be appreciated.


回答1:


I have an API level check and do something a bit different for anything less than Jelly Bean:

if(jellybeanOrHigher())
{
///Jelly bean 
}
else
{  
    NotificationCompat2.Builder mBuilder = new NotificationCompat2.Builder(this.context)
            ........
}

That might get around it for you. It took me quite a while to get notifications setup so this was what worked for me.



来源:https://stackoverflow.com/questions/15371200/notification-doesnt-show-in-ginger-bread-but-works-in-jellybean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!