问题
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.
回答1:
In the phone's system settings -> accesivility service I had to enable my app. After that it started to work.
回答2:
try Thread.sleep(1000)
before performGlobalAction()
来源:https://stackoverflow.com/questions/29200046/accessibility-service-performglobalaction-returns-false