首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单击通知后关闭通知

单击通知后关闭通知
EN

Stack Overflow用户
提问于 2018-02-02 16:01:01
回答 1查看 67关注 0票数 0

我创建了一个通知,但是一旦我点击它,它就不会被删除!我甚至尝试过notification.setAutoCancel(true)notification.getNotification().flags |= Notification.FLAG_AUTO_CANCEL

下面是我的代码:

代码语言:javascript
复制
notification.setSmallIcon(R.drawable.message64);
Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notification.setSound(uri);

Resources resources = getApplicationContext().getResources(),
            systemResources = Resources.getSystem();
notification.setTicker("Notification");
notification.setContentTitle("Nouveau message");
notification.setContentText("Vous avez reçu un nouveau message. ");
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(pendingIntent);

NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notification.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
nm.notify(uniqueID,notification.build());

它工作得很好,但当我点击它时,它仍然不能删除它。

EN

回答 1

Stack Overflow用户

发布于 2018-02-02 16:31:16

代码语言:javascript
复制
 NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setWhen(System.currentTimeMillis())
            .setLargeIcon(BitmapFactory.decodeResource(getResources(),
                    R.mipmap.ic_launcher))
            .setContentTitle(getString(R.string.app_name))
            .setAutoCancel(true)

            .setContentText("Test")



    getManager().notify(ID, builder.build());

使用setAutoCancel(true)是否在单击时清除通知

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48578222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档