通知未被驳回(Android)

通知未被驳回(Android),第1张

概述如果单击“ *** 作”,则通知setAutoCancel(true)不起作用 我有一个通知,其中包含一个动作.当我点击通知时,它会从列表中删除.但是,当我单击Action它成功完成Action(即调用)时,但当我返回到通知列表时,它仍然存在. AlarmReceiver的相对代码: public class AlarmReceiver extends BroadcastReceiver {Meetin 如果单击“ *** 作”,则通知setautoCancel(true)不起作用

我有一个通知,其中包含一个动作.当我点击通知时,它会从列表中删除.但是,当我单击Action它成功完成Action(即调用)时,但当我返回到通知列表时,它仍然存在.
AlarmReceiver的相对代码:

public class AlarmReceiver extends broadcastReceiver {Meeting meeting;/** * Handle received notifications about meetings that are going to start */@OverrIDepublic voID onReceive(Context context,Intent intent) {    // Get extras from the notification intent    Bundle extras = intent.getExtras();    this.meeting = extras.getParcelable("MeetingParcel");    // build notification pending intent to go to the details page when click on the body of the notification    Intent notificationIntent = new Intent(context,MeetingDetails.class);    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    notificationIntent.putExtra("MeetingParcel",meeting);      // send meeting that we received to the MeetingDetails class    notificationIntent.putExtra("notificationIntent",true);    // flag to kNow where the details screen is opening from    PendingIntent pIntent = PendingIntent.getActivity(context,notificationIntent,0);    // build intents for the call Now button    Intent phoneCall = Call._callintent(meeting);    if (phoneCall != null) {        PendingIntent phoneCallintent = PendingIntent.getActivity(context,phoneCall,PendingIntent.FLAG_CANCEL_CURRENT);        int flags = Notification.FLAG_auto_CANCEL;        // build notification object        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);        Notification notification = builder.setContentTitle("Call In")                .setContentText(intent.getStringExtra("contextText"))                .setTicker("Call In Notification")                .setcolor(ContextCompat.getcolor(context,R.color.colorBluePrimary))                .setautoCancel(true)                    // will remove notification from the status bar once is clicked                .setDefaults(Notification.DEFAulT_ALL)  // Default vibration,default sound,default LED: requires VIBRATE permission                .setSmallicon(R.drawable.icon_notifications)                .setStyle(new NotificationCompat.BigTextStyle()                        .bigText(meeting.description))                .addAction(R.drawable.icon_device,"Call Now",phoneCallintent)                .setcategory(Notification.category_EVENT)   // handle notification as a calendar event                .setPriority(Notification.PRIORITY_HIGH)    // this will show the notification floating. Priority is high because it is a time sensitive notification                .setContentIntent(pIntent).build();        notification.flags = flags;        // tell the notification manager to notify the user with our custom notification        notificationmanager notificationmanager = (notificationmanager) context.getSystemService(Context.NOTIFICATION_SERVICE);        notificationmanager.notify(0,notification);    }  }}

解决方法 我今天遇到了这个问题,发现FLAG_auto_CANCEL和setautoCanel(true)都在点击通知时起作用,
但不适合行动点击

简单地说,在目标服务或行动活动中,取消通知

notificationmanager manager = (notificationmanager) this.getSystemService(Context.NOTIFICATION_SERVICE);manager.cancelAll();

或者如果有更多通知

manager.cancel(notificationID);
总结

以上是内存溢出为你收集整理的通知未被驳回(Android)全部内容,希望文章能够帮你解决通知未被驳回(Android)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1123803.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存