Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessibility Service - performGlobalAction() returns false

I am creating an Android Accessibility Service which calls performGlobalAction() at onStartCommand()

public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d("service", "started");
    Bundle extras = intent.getExtras();
    Integer value = -1;
    if (extras != null) {
        value = extras.getInt("control");
    }

    switch(value) {
        case BUTTON_EVENT_BACK:
            //press back button
             boolean result = performGlobalAction(GLOBAL_ACTION_BACK);
             Log.d("make back action result: ", Boolean.toString(result));
            break;          
        }
    stopSelf();
    return Service.START_STICKY;

}

I followed the guide and add necessary permissions to the manifest.

<service android:name=".MyAccessibilityService"
    android:label="@string/app_name"
    android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
  <intent-filter>
    <action android:name="android.accessibilityservice.AccessibilityService" />
  </intent-filter>
</service>

and

<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />

So my question is why the function call returns false. What is missing? And back button press event not happening by the way.

like image 412
laplasz Avatar asked Mar 22 '15 21:03

laplasz


1 Answers

In the phone's system settings -> accesivility service I had to enable my app. After that it started to work.

like image 196
laplasz Avatar answered Sep 16 '22 17:09

laplasz