Android派未调用onAccessibilityEvent

时间:2019-04-13 09:18:28

标签: android accessibilityservice

onAccessibilityEvent从未在Android Pie上调用。 首先,这是我的代码

public class MyAccessibilityService extends AccessibilityService  {

    @Override
    public void onInterrupt() {
    }

    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
        final int eventType = event.getEventType();
        switch(eventType) {
            case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED:
                Log.e("called called ","nnnnnnnnnnnnnnn TYPE_VIEW_TEXT_CHANGED "+visibility);
                show();
                break;
            case AccessibilityEvent.TYPE_VIEW_FOCUSED:
                break;
        }
    }

    @Override
    protected void onServiceConnected() {
        super.onServiceConnected();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}

这是我的清单服务

<service
    android:name=".service.MyAccessibilityService"
    class=".MyAccessibilityService"
    android:enabled="true"
    android:exported="false"
    android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
    <intent-filter>
        <action android:name="android.accessibilityservice.AccessibilityService" />
    </intent-filter>

    <meta-data
        android:name="android.accessibilityservice"
        android:resource="@xml/serviceconfig" />
</service>

和serviceConfig xml

<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:description="@string/app_name"
    android:accessibilityEventTypes="typeViewTextChanged|typeViewFocused"
    android:accessibilityFeedbackType="feedbackAllMask"
    android:notificationTimeout="20"
    android:canRetrieveWindowContent="true"
/>

onServiceConnected被无问题调用,并且onDestroy从未被调用,因此,我的服务也不会被杀死。 onAccessibilityEvent并未被调用,但是当我在较旧的版本(例如4.4.4)上对其进行测试时 和7.0起作用。但是,在Pie onAccessibilityEvent上永远不会被调用

1 个答案:

答案 0 :(得分:0)

要尝试的一件事是删除notificationTimeout。该参数未经充分测试。