0

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

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!

Community
  • 1
  • 1
Piero
  • 189
  • 1
  • 2
  • 11

2 Answers2

1

This worked for me on Android 4.1.1, but failed on Android 4.2(Jelly Bean) .You also have to add a value-v17 folder to account for the SDK change. Check this solution https://stackoverflow.com/a/12042493/1179638

Community
  • 1
  • 1
Atul Bhardwaj
  • 6,647
  • 5
  • 45
  • 63
0

I had the same issue with you, please try this method. Add the <category android:name="android.accessibilityservice.category.FEEDBACK_SPOKEN" /> in the intent filter.

AccessibilityService is started but does not receive AccessibilityEvents on JellyBean

Community
  • 1
  • 1
HackNone
  • 504
  • 6
  • 12