没有收到TYPE_TOUCH_INTERACTION_START类型的任何AccessibilityEvent

时间:2013-06-20 13:01:15

标签: android touch accessibility

我正在尝试创建一个重新映射触摸输入的AccessibilityService,因此我需要拦截触摸事件。

我注意到API 17(Android 4.2)中添加了TYPE_TOUCH_INTERACTION_STARTTYPE_TOUCH_INTERACTION_END类型的AccessibilityEvent。

但是,当我在Android 4.2模拟器上测试我的代码,目标API 17时,我无法接收此类事件,但所有其他事件(例如TYPE_VIEW_CLICKED)都已正确接收。

我错过了什么吗?

我的AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.onthewings.touchservice"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <service android:name=".TouchService"
            android:label="TouchService"
            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/accessibility_service_config" />
        </service>

    </application>

</manifest>

我的accessibility_service_config.xml:

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityEventTypes="typeAllMask"
    android:accessibilityFlags="flagIncludeNotImportantViews"
    android:accessibilityFeedbackType="feedbackVisual"
    android:notificationTimeout="0"
    android:canRetrieveWindowContent="true"
/>

2 个答案:

答案 0 :(得分:1)

只有当“触摸探索模式”开启时(通过任何服务),才会收到TYPE_TOUCH_INTERACTION_STARTTYPE_TOUCH_INTERACTION_END

答案 1 :(得分:0)

应添加

android:accessibilityFlags="*|flagRequestTouchExplorationMode" android:canRequestTouchExplorationMode="true"

<accessibility-service>节点中:

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityEventTypes="typeAllMask"
    android:accessibilityFeedbackType="feedbackGeneric"
    android:accessibilityFlags="flagDefault|flagIncludeNotImportantViews|flagRequestTouchExplorationMode"
    android:canPerformGestures="true"
    android:canRequestTouchExplorationMode="true"
    android:canRetrieveWindowContent="true"
    android:description="@string/accessibility_description"
    android:notificationTimeout="50" />