博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android accessibility service detect notification
阅读量:6280 次
发布时间:2019-06-22

本文共 3424 字,大约阅读时间需要 11 分钟。

hot3.png

0 down vote

I'm trying to make my app detect whenever a notification is displayed. I've enabled it in the settings app andonServiceConnecteddoes get called, however when I create a notification or receive an e-mail through the gmail app nothing happens,onAccessibilityEventdoes not get called.

Android manifest:

NotificationService.java

package com.test.slide; import android.accessibilityservice.AccessibilityService; import android.accessibilityservice.AccessibilityServiceInfo; import android.view.accessibility.AccessibilityEvent; public class NotificationService extends AccessibilityService {
@Override public void onAccessibilityEvent(AccessibilityEvent event) {
System.out.println("onAccessibilityEvent"); if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
System.out.println("notification: " + event.getText()); } } @Override protected void onServiceConnected() {
System.out.println("onServiceConnected"); AccessibilityServiceInfo info = new AccessibilityServiceInfo(); info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED; info.notificationTimeout = 100; info.feedbackType = AccessibilityEvent.TYPES_ALL_MASK; setServiceInfo(info); } @Override public void onInterrupt() {
System.out.println("onInterrupt"); } }

Thanks for any help.

|
edited
asked Sep 23 '12 at 17:18
396 1 4 20
Did you found the solution? i have exactly the same problem. – 
alanv's answer worked for me – 
For what system version are you programming? ICS? jelly bean? – 
Jelly bean 4.1.1 – 

2 Answers

up vote 2 down vote accepted

Accessibility services in Android 4.0 and above can behave strangely if there is no meta-data tag defined in the manifest. Try defining the meta-data as in the examples below. You should continue to use setServiceInfo() to maintain backward compatibility with pre-4.0 devices.

Also, I would recommend specifying a feedback type that is specific to your service, rather than using "all".

AndroidManifest.xml

res/xml/accessibilityservice.xml

There was an error in your feedbackType. Corrected below. Still, consider using a more specific feedback type.

NotificationService.java

@Override protected void onServiceConnected() {
AccessibilityServiceInfo info = new AccessibilityServiceInfo(); info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED; info.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK; info.notificationTimeout = 100; setServiceInfo(info); }
|
edited
answered Sep 24 '12 at 1:33
442 1 10
Now you are defining theserviceInfoin XML and code. You may leave out the code part of AccessibilityServiceInfo because the xml is defined in the manifest. – 
1  
On the contrary, you must define it in both places for compatibility with pre-ICS devices. – 
27002600_pP5a.gif
up vote 1 down vote

The app using AccessibilityService needed to have a permission from settings>Accessibility in order to access the system events. Allow permission from settings . This may work

check this link

转载于:https://my.oschina.net/zhuzihasablog/blog/110534

你可能感兴趣的文章
modprobe
查看>>
android中用ExpandableListView实现三级扩展列表
查看>>
%Error opening tftp://255.255.255.255/cisconet.cfg
查看>>
java读取excel、txt 文件内容,传到、显示到另一个页面的文本框里面。
查看>>
《从零开始学Swift》学习笔记(Day 51)——扩展构造函数
查看>>
python多线程队列安全
查看>>
[汇编语言学习笔记][第四章第一个程序的编写]
查看>>
android 打开各种文件(setDataAndType)转:
查看>>
补交:最最原始的第一次作业(当时没有选上课,所以不知道)
查看>>
Vue实例初始化的选项配置对象详解
查看>>
PLM产品技术的发展趋势 来源:e-works 作者:清软英泰 党伟升 罗先海 耿坤瑛
查看>>
vue part3.3 小案例ajax (axios) 及页面异步显示
查看>>
浅谈MVC3自定义分页
查看>>
.net中ashx文件有什么用?功能有那些,一般用在什么情况下?
查看>>
select、poll、epoll之间的区别总结[整理]【转】
查看>>
CSS基础知识(上)
查看>>
PHP中常见的面试题2(附答案)
查看>>
26.Azure备份服务器(下)
查看>>
mybatis学习
查看>>
LCD的接口类型详解
查看>>