6

我正在创建一个调用performGlobalAction()的Android辅助功能服务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;

}

我按照指南向清单添加了必要的权限。

<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。什么不见​​了?顺便说一句,后退按钮按下事件没有发生。

4

2 回答 2

1

在手机的系统设置-> 访问服务中,我必须启用我的应用程序。之后它开始工作。

于 2015-03-22T23:55:13.657 回答
0

Thread.sleep(1000)之前尝试performGlobalAction()

于 2017-07-24T09:49:02.660 回答