辅助功能服务 - performGlobalAction()返回false

时间:2015-03-22 21:25:11

标签: android accessibilityservice

我正在创建一个Android Accessibility Service,在onStartCommand()

调用performGlobalAction()
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;

}

我按照指南操作并为清单添加了必要的权限。

<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>

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

所以我的问题是为什么函数调用返回false。缺什么?顺便说一句,后退按钮事件不会发生。

2 个答案:

答案 0 :(得分:1)

在手机的系统设置中 - &gt; accessivility服务我必须启用我的应用程序。之后它开始起作用了。

答案 1 :(得分:0)

Thread.sleep(1000)

之前尝试performGlobalAction()
相关问题