1

我正在使用无障碍服务做一些任务。一切都很好,但我需要删除我的 xml 配置并从 onServiConnected 配置方法运行服务,这就是我遇到问题的地方。

当我在手机中启用服务时,我可以在日志中看到 onServiceConnected 有效,但它不适用于包名称,就像我在 access_xml_config 中运行配置的位置一样。

然后,我想做的是具有与 access_xml_config 相同的功能,但在 onServiceConnected 方法中。

我的方法:

@Override
    @SuppressLint("NewApi")
    public void onServiceConnected() {
        super.onServiceConnected();
        Log.i(TAG, "onServiceConnected AccessibilityService");
        AccessibilityServiceInfo info = new AccessibilityServiceInfo();
        info.flags = AccessibilityServiceInfo.DEFAULT;
        info.getCanRetrieveWindowContent();
        info.notificationTimeout = 100;
        info.feedbackType = AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS;
        info.feedbackType = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
        info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
        info.feedbackType = AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS;
        info.packageNames = new String[]{"com.android.incallui"};
        this.setServiceInfo(info);

    }

显现

 <service android:name=".VsAccessibilityCallScreenService"
            android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
            <intent-filter>
                <action android:name= "android.accessibilityservice.AccessibilityService" />
            </intent-filter>

这是我的 access_xml_config:

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:packageNames="com.android.incallui"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFlags="flagDefault|flagReportViewIds|flagIncludeNotImportantViews|flagRetrieveInteractiveWindows"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="100"
android:canRetrieveWindowContent="true"
android:description="@string/app_name"
    />
4

2 回答 2

1

您以错误的方式使用位/整数标志分配:)

    info.feedbackType = AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS;
    info.feedbackType = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
    info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
    info.feedbackType = AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS;

每下一行都覆盖前一行

所以对于你的情况,它应该是

    info.feedbackType = 
      AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS
    | AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS
    | AccessibilityServiceInfo.FEEDBACK_GENERIC
    | AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS; 

简而言之:

&   -  bitwise and
|   -  bitwise or
^   -  bitwise xor
~   -  bitwise not
<< -  bitwise shift left
>>  -  bitwise shift right

好的开始:

于 2019-10-03T16:36:58.767 回答
-2

我找到了答案...使用 getServiceInfo();

@Override
    @SuppressLint("NewApi")
    public void onServiceConnected() {
        super.onServiceConnected();
        Log.i(TAG, "onServiceConnected AccessibilityService");
        accessibilityServiceInfo info;
        clientconfig = VsClientConfig.getInstance();
        info = getServiceInfo();
        info.packageNames = new String[]{"your.package.name"};
        setServiceInfo(info);

    }
于 2016-02-25T14:28:17.690 回答