相关疑难解决方法(0)

NotificationManager.cancel(id)在广播接收器内不起作用

Android:我正在尝试在安装软件包后取消通知栏中的通知.我正在做的是以下内容:

 public class MyBroadcastReceiver extends BroadcastReceiver {

                private static final String TAG = "MyBroadcastReceiver";

                @Override
                public void onReceive(Context context, Intent intent) {
                    String action = intent.getAction();
                    if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
                        Uri data = intent.getData();
                        //some code goes here
                        //get the id of the notification to cancel in some way
                        notificationhelper._completeNotificationManager.cancel(id);     
                        }
                }
            }
Run Code Online (Sandbox Code Playgroud)

哪里

public class notificationhelper {
    public static NotificationManager _completeNotificationManager = null;

    public void complete() {        
        if (_completeNotificationManager == null)
            _completeNotificationManager = (NotificationManager) _context.getSystemService(Context.NOTIFICATION_SERVICE);
            Notification notification = new Notification( …
Run Code Online (Sandbox Code Playgroud)

android broadcastreceiver notificationmanager

10
推荐指数
3
解决办法
2万
查看次数