I’m trying to launch a non cancellable ongoing notification but no matter what I try it is cancellable.
code:
NotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.btn_rating_star_on_pressed_holo_light;
long when = System.currentTimeMillis();
notification = new Notification(icon, getString(R.string.notificationMSG), when);
notification.ledARGB = 999;
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, Notification.FLAG_ONGOING_EVENT + Notification.FLAG_NO_CLEAR + Notification.FLAG_SHOW_LIGHTS);
notification.setLatestEventInfo(context, getString(R.string.app_name), getString(R.string.notificationMSG), contentIntent);
notificationManager.notify(Global.NOTIFICATION_ID,notification);
I would also like to know how to make it go away once the activity that launched it is finished. Tried doing the following but it works only some times.
@Override
protected void onDestroy(){
notificationManager.cancel(Global.NOTIFICATION_ID);
super.onDestroy();
}
For some stupid reason we cannot put the flags directly in the
PendingIntentand need to set them this way instead.