gpt4 book ai didi

android - 如何在Android应用程序中点击后隐藏通知

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:49:44 24 4
gpt4 key购买 nike

这是在服务开始时发出通知的代码

NotificationCompat.Builder mbuild = new NotificationCompat.Builder(getApplicationContext());

Intent in = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent resultIN = PendingIntent.getActivity(getApplicationContext(),code,in,NOTIFICATION_COUNT); mbuild.setSmallIcon(R.drawable.images1);
mbuild.setContentText(NOTIFICATION_COUNT +" New Message");
mbuild.setContentIntent(resultIN); //mbuild.addAction(R.drawable.notifications,NOTIFICATION_COUNT +"New Messages",resultIN);

NotificationManager nmagr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nmagr.notify(1, mbuild.build());

一切正常..代码打开了目标 Activity ,但通知仍然停留在通知栏中。我试过使用 mbuil.setautocancel(true);但它什么也没做

最佳答案

试试这个

NotificationManager nmagr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification=mbuild.build();
notification.flags = Notification.FLAG_AUTO_CANCEL;
nmagr.notify(1,notification);

关于android - 如何在Android应用程序中点击后隐藏通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22217416/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com