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.
In the phone's system settings -> accesivility service I had to enable my app. After that it started to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With