关闭通过swip

时间:2015-12-16 08:43:28

标签: android notifications

我有一个可以播放某些媒体和应用媒体的应用程序可以从通知栏播放或暂停。现在我想在用户通过刷卡从手机的应用列表中删除应用时关闭通知。我知道活动onDestroy()方法不会调用。

这是我的代码的一部分:

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

在我的主要活动中,我有这种方法:

 public void showNotification() {
    myNotification = new MyNotification(this);
}

现在该怎么办???? TNX

0 个答案:

没有答案