删除点击通知(不重复)

时间:2018-02-08 17:39:13

标签: android notifications foreground-service

请不要在没有完整阅读问题的情况下将此标记为重复,因为有很多类似的问题。

我的问题正如标题所说: 我使用前台服务来显示静态通知。我希望在用户单击通知时删除通知。 我知道我的代码中必须遗漏一些东西:

Notification notification = new Notification.Builder(this)
                .setContentTitle("Truiton Music Player")
                .setTicker("Truiton Music Player")
                .setContentText("My Music")
                .setSmallIcon(R.drawable.ic_android)
                .setContentIntent(pendingIntent)
                .setOngoing(true)
                .addAction(android.R.drawable.ic_media_previous,
                        "Previous", ppreviousIntent)
                .addAction(android.R.drawable.ic_media_play, "Play",
                        pplayIntent)
//              .setAutoCancel(true)
                .addAction(android.R.drawable.ic_media_next, "Next",
                        pnextIntent).build();
//              notification.flags = Notification.FLAG_AUTO_CANCEL;
        startForeground(100, notification);

评论的行是我尝试过但没有运气的行。

0 个答案:

没有答案