问题
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