android 广播失效,android – NotificationManager.cancel(id)在广播接收器中不起作用

news/2024/7/8 5:22:20

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);

}

}

}

哪里

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(

R.drawable.notification,

_context.getString(R.string.notification),

System.currentTimeMillis());

notification.flags |= Notification.FLAG_AUTO_CANCEL;

notification.flags |= Notification.FLAG_NO_CLEAR;

_completeNotificationManager.notify(TEXT, id, notification);

}

}

但是notificationhelper._completeNotificationManager.cancel(id)不起作用.我试着使用notificationhelper._completeNotificationManager.cancelAll();它的工作原理.我做错了什么?


http://www.niftyadmin.cn/n/1996604.html

相关文章

春运购买火车票、乘车攻略

春运购买火车票、乘车攻略 author: 忘情 一年一度的春运又开始了。每年到了这时候,为了买火车票,许多人都头皮发麻吧?作为一名打小就在铁路上长大的铁路职工,尽我所掌握的情况,给大家谈谈春运买票,乘车攻…

Oracle列自增-12c

在ORACLE 12C以前的版本中,如果要实现列自增长,需要通过序列触发器实现,到了12C ORACLE 引进了Identity Columns新特性,从而实现了列自增长功能。 一、Identity Columns使用语法 GENERATED[ ALWAYS | BY DEFAULT [ ON NULL ] ]AS IDENTITY [ ( identity_options ) ]identity_op…

编译 android 内核,[原创]安卓内核驱动编译方法

设置完这些基本上就ok了。首先我们要编译的一种是可动态加载的内核驱动。去到 goldfish/drivers 文件夹创建一个文件夹。就叫helloworld吧。不过其实对于这种动态加载的内核驱动,不一定需要在这个drivers文件夹下面,因为最后只要得到那个ko模块就好了。在…

美国25大高薪公司

美国25大高薪公司 排名 公司 平均薪酬 行业 1 Bingham McCutchen 21.1017万美元 法律事务 2 Arnold & Porter 19.4575万美元 法律事务 3 Alston & Bird 19.0135万美元 法律事务 4 Shared Technologies 18.7137万美元 电信系统 5 Nixon Peabody 17.8016万美元 法律事务…

Android 使用ArrayAdapter 加载Bean数据

在Android中 我们经常使用到ListView GridView RecyclerView,Adapter 通常是继承自BaseAdapter/RecyclerView.Adapter 但开发中也可能需要展示的数据只有一个标题或者属性,自定义Adapter显得有些囊肿,但ArrayAdaprer 很多资料都是使用ArrayLi…

有点小变态的模板程序

有点小变态的模板程序 #include "stdafx.h"#include <iostream> using namespace std; template <class T>class B1{public: void SayHi() { T* pT static_cast<T*>(this); // HUH?? 我将在下面解释 pT->PrintClassName(); …

android网络编程 英语,Android网络编程之Http通信

Android中提供的HttpURLConnection和HttpClient接口可以用来开发HTTP程序。以下是本人在学习中的总结与归纳。1. HttpURLConnection接口 首先需要明确的是&#xff0c;Http通信中的POST和GET请求方式的不同。GET可以获得静态页面&#xff0c;也可以把参数放在URL字符串后面&…

android jar包 下载地址,Android Studio项目依赖包下载到本地的jar或aar的路径

版权声明&#xff1a;本文为博主原创文章&#xff0c;遵循 CC 4.0 BY-SA 版权协议&#xff0c;转载请附上原文出处链接和本声明。本文链接&#xff1a;https://blog.csdn.net/chenzhengfeng/article/details/83541031Android Studio项目中添加的依赖&#xff0c;会自动到maven库…