In my code, I create a notification that once clicked tries to uninstall an app identified by its package name. I want the notification to be disappear only if the app is successfully uninstalled. If the user clicks "cancel" for app uninstall pop-up, I would like the notification to persist.
Any ideas how I can do that?
Uri packageURI = Uri.parse("package:" + package_name);
Intent intent = new Intent(Intent.ACTION_DELETE, packageURI);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pintent=PendingIntent.getActivity(context,0,intent,0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentIntent(pintent);
builder.setContentTitle(uninstallAppNotificationTitle);
builder.setTicker(uninstallAppNotificationTicker);
builder.setContentText(uninstallAppNotificationContent);
builder.setWhen(System.currentTimeMillis());
builder.setAutoCancel(true);
builder.setDefaults(Notification.DEFAULT_ALL);
builder.setSmallIcon(android.R.drawable.ic_dialog_alert);
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(uninstallAppNotificationContent)) ;
builder.setPriority(Notification.PRIORITY_MAX);
builder.setOngoing(true);
Notification notification = builder.build();
notification.contentIntent = pintent;
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(TAG, uninstallNotificationId, notification);