I'm trying to receive accessibility events on an android phone with Jelly bean (Android version 4.1.1).
I've seen several question that address this problem (specially regarding the compatibility between JB and pre JB):
Android accessibility service detect notification
AccessibilityService is started but does not receive AccessibilityEvents on JellyBean
Android accessibility service backwards compatibility and jelly bean
According to all these question (specially the last one) if I don't want to ensure backward compatibility all I need to do is to add the line
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
in my manifest file and to include the xml configuration file.
I did this, but still I can't receive the onAccessibilityEvent notifications when a notification is posted in the notification bar. Here is my code
public class NotificationService extends AccessibilityService {
private static final Logger logger = LoggerFactory.getLogger ("NotificationService");
@Override
public void onCreate()
{
super.onCreate();
logger.trace ("onCreate");
}
@Override
public void onDestroy()
{
super.onDestroy();
logger.trace ("onDestroy");
}
@Override
protected void onServiceConnected() {
logger.trace("onServiceConnected");
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK;
info.notificationTimeout = 100;
setServiceInfo(info);
}
@Override
public void onInterrupt() {
// TODO Auto-generated method stub
}
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
logger.trace("onAccessibilityEvent");
if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
logger.info("notification: " + event.getText());
}
}
}
Here is how I declare the service in the manifest file
<service android:name=".NotificationService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data android:name="android.accessibilityservice"
android:resource="@xml/accessibilityservice" />
</service>
Here is my accessibilityservice.xml
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://Schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeNotificationStateChanged"
android:accessibilityFeedbackType="feedbackAllMask"
android:notificationTimeout="100" />
When I run my app I can see that the service is created and it connects, but no AccessibilityEvents are received.
Thanks!