I have an app that play some media and media can be played or paused from notification bar.now I want to close notification when user remove app from his phone's app list by swiping.I know that the activity onDestroy()
method does not call.
here is some part of my code:
public class MyNotification extends Notification {
private Context ctx;
private NotificationManager mNotificationManager;
RemoteViews mContentView;
@SuppressLint("NewApi")
public MyNotification(Context ctx) {
super();
this.ctx = ctx;
String ns = Context.NOTIFICATION_SERVICE;
mNotificationManager = (NotificationManager) ctx.getSystemService(ns);
CharSequence tickerText = G.lastPlayingBookMaster.getName();
long when = System.currentTimeMillis();
Notification.Builder builder = new Notification.Builder(ctx);
@SuppressWarnings("deprecation")
Notification notification = this;
notification.when = when;
notification.tickerText = tickerText;
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
notification.icon = R.drawable.icon_notification_white;
}else{
notification.icon = R.drawable.icon_launcher;
}
mNotificationManager.notify(548853, notification);
}
}
And in my main activity I have this method:
public void showNotification() {
myNotification = new MyNotification(this);
}
Now what can I do???? tnx