Accessibility Service - performGlobalAction() returns false

╄→尐↘猪︶ㄣ 提交于 2019-12-19 09:04:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!