Android 通知删除事件监听,截获通知

 安卓12广播

if(this.getPackageName() !=null){intent.setPackage(this.getPackageName());
}
F01AMainActivity.this.sendBroadcast(intent);

 

Intent intentCancel = new Intent(getApplicationContext(),NotificationBroadcastReceiver.class);
PendingIntent pendingIntentCancel = PendingIntent.getBroadcast(getApplicationContext(),0,intentCancel,PendingIntent.FLAG_ONE_SHOT);
 
 
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);

mBuilder.setDeleteIntent(pendingIntentCancel)//取消消息回调

 

/*** ProjectName: Myditukaifa* Author: lgq* Date: 2018/3/12 0012 15:26*/
public class NotificationBroadcastReceiver extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {String action = intent.getAction();int type = intent.getIntExtra("type", -1);if (type != -1) {NotificationManager notificationManager =(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);notificationManager.cancel(type);}//        if (action.equals("notification_cancelled")) {//处理滑动清除和点击删除事件Log.i("lgqq","body=====7777777777777777=NotificationBroadcastReceiver===="+action);
//        }ShareUtil.sharedPint("ifnotifica",0);}
}

配置

<receiver android:name=".NotificationBroadcastReceiver"><intent-filter><action android:name="notification_cancelled" /></intent-filter></receiver>

方法2:

public class MessageNotificationService extends NotificationListenerService {@Overridepublic void onNotificationRemoved(StatusBarNotification sbn) {super.onNotificationRemoved(sbn);Log.e("--------------", "--------------------------");//删除通知}@Overridepublic void onNotificationPosted(final StatusBarNotification sbn) {final Notification mNotification = sbn.getNotification();if (mNotification != null) {Log.e("返回通知发起的时间=", sbn.getPostTime() + "");Log.e("发送通知的包名=", sbn.getPackageName() + "");Log.e("通知内容=", mNotification.tickerText + "");}}
}
<serviceandroid:name=".test2.MessageNotificationService"android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"><intent-filter>             <action android:name="android.service.notification.NotificationListenerService">               </action>       </intent-filter>
</service>

Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
startActivity(intent);

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/415722.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

小程序设置页面背景颜色

首先&#xff0c;我使用的是mpvue开发。样式使用的less&#xff0c;并且全局会定义一套主题。 primary-color : #ff8730; second-color : #F48B4A; background-color :#F3F3F3; second-text-color :#787878;.flex-center-row {display: flex;flex-d…

【UVA 437】The Tower of Babylon(拓扑排序+DP,做法)

【Solution】 接上一篇,在处理有向无环图的最长链问题的时候,可以在做拓扑排序的同时,一边做DP; 设f[i]表示第i个方块作为最上面的最高值; f[y]max(f[y],f[x]h[y]);(x−>y)∈E 这样可以保证,按阶段进行DP,每次在获取f[x]的时候,你可以保证f[x]已经获得了; 最后取max(f[1…

Cass2008 for CAD2006 安装

1、首先安装CAD2006&#xff0c;装完破解&#xff0c;注&#xff1a;默认路径安装。 2、安装Cass2008 for cad2006,装完以后&#xff0c;打补丁1、补丁2 。注&#xff1a;默认路径安装。 3、将haitusoft 、 debug放在D盘根目录下&#xff0c;这个是公司自己开发的&#xff0c…

android Handler Message传递参数,handler子线程和主线程通讯

创建Handler private Handler handler new Handler() {Overridepublic void handleMessage(Message msg) {switch(msg.what){case 1 : String str1 msg.getData().getString("text1");//接受msg传递过来的参数String str2 msg.getData().getString("text2&…

hapi 使用 lab 和 code 进行测试

测试库有很多&#xff0c;我选了lab。 1、安装lab和code yarn add lab code2、创建test文件夹 test文件夹里面的js文件会被跑测试。比如创建index.js。 const { expect } require(code); const Lab require(lab); const lab exports.lab Lab.script();lab.test(returns t…

远程桌面无法连接服务器,启动Terminal Services 服务报1053错误

今天碰到一棘手问题&#xff0c;一上午数据库服务器都无法连接&#xff0c;远程桌面也连不上了&#xff0c;但是可以PING通。项目组的同事一直反映数据库无法连接&#xff0c;耽误工作进度&#xff0c;真急人啊。 跑到机房一看&#xff0c;机器轰轰巨响&#xff0c;进入桌面&a…

【codeforces 534D】Handshakes

【题目链接】:http://codeforces.com/contest/534/problem/D 【题意】 n个人依次进入一个房间; 进进来的人会和房间里面没有组队的人握一次手; (这里的握手只计算主动握手的那个人的握手次数); (任意时刻,任意3个人都能组队)&#xff1b; 给出每个人的握手信息; 问你n个…

lab 常用配置参数 代码片段

1、--leaks 启用内存泄漏检测&#xff0c;并在检测到时向您发出警告 2、代码片段 experiment(getting started with hapi testing,, () > {// 这种写法会跳过测试test(lab considers this test as TOOD and skips it)// 这种写法不会跳过测试test(always succeeding :), (…

android 底部表格布局TableLayout

添加依赖compile com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2aar置于底部布局&#xff08;最外层必须是RelativeLayout&#xff09;<?xml version"1.0" encoding"utf-8"?> <RelativeLayout xmlns:android"http://schemas.android.com/a…

Arcgis10安装说明

1、 先安装dotnet framework 3.5 ,必须要装这个才能运行安装程序。 2、 接着安装Arcgis Desktop &#xff0c;只需下一步&#xff0c;下一步执行就好了。完成后&#xff0c;停掉服务。 3、 安装LicenseManager &#xff0c;下一步执行就可以。 4、 接着来破解&…

前端学习(2606):vue简单叙述

第一步 引入 第二步new Vue 第三步 data绑定数据

wux-button 样式扩展 增加shape属性

1、原来的写法和界面图如下 <wux-button block type"orange">拍照确认</wux-button>2、现在的写法只需要增加一个shape"round"参数&#xff0c;可以实现按钮边框为半圆 <wux-button block type"orange" shape"round"&g…

android webView注入js方法

需要在页面加载完成之后才能注入自定义js方法 webView.setWebViewClient(new WebViewClient() {Overridepublic boolean shouldOverrideUrlLoading(WebView view, String url) { // view.loadUrl(url);return true;//true时&#xff0c;不可点击跳页效果&…

前端框架Bootstrap简单介绍

下载&#xff1a; 解压之后&#xff1a; 把这些文件拷贝到项目中 页面使用时 只需要引入&#xff1a; 然后我们就可以参考官网来设计需要的前端页面了 设计一个按钮&#xff1a;button 只需要标明css样式中使用的类 下面就是现实效果&#xff1a; 转载于:https://www.cnblo…

CASS软件学习笔记

最近需要学习数据处理&#xff0c;用到的软件是Cass6.1 软件&#xff0c;下面我将学习中的笔记进行了整理。 1、Cass 6.1 支持是CAD2004 &#xff0d;2006&#xff0c;安装的话&#xff0c;先装CAD&#xff0c;然后破解&#xff0c;再装Cass &#xff0c;然后打上补丁&#xf…

vue学习中遇到的错误 Duplicate keys detected: ‘[object Object]‘. This may cause an update error.

前端入门自学&#xff0c;说错的请大神指点。 Avoid using non-primitive value as key, use string/number value instead. Duplicate keys detected: ‘[object Object]’. This may cause an update error.运行后出现这些警告&#xff0c;意思是检测到重复的键值。 把:key里…

mongoose 数据库设计千万要注意 Cast to [number] failed for value

不要定义字段type balance_flow: [{// 提现金额money: { type: Number },// 资金类型 0>提现 withdraw 1>资金流入 user_activetype: Number}],这样会报错

Linux Shell中有三种引号的用法

Linux Shell中有三种引号&#xff0c;分别为双引号&#xff08;" "&#xff09;、单引号( )以及反引号( )。 其中双引号对字符串中出现的$、、和\进行替换&#xff1b;单引号不进行替换&#xff0c;将字符串中所有字符作为普通字符输出&#xff0c;而反引号中字符串作…