Search code examples
androidqt-quickaccessibilityservice

Qt Quick Android : How to integrate an Accessibility Service


I'm working on an Android application which runs an accessibility service. I have developed the service java class and configuration xml files in Android Studio to test it as native app. When I run it, the accessibility service appears in the Android Accessibility Settings as expected and I can enable it.

However I would like to integrate this service in a Qt Quick Android application. When I do this by adding the same java class, Manifest and configuration xml files, the project compiles and runs well but the service doesn't appear in Android Settings.

Here are my configuration files:

Manifest.xml:

<activity
...
</activity>
<service android:name="com.myCompany.app.MyService"
         android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
        <intent-filter>
            <action android:name="android.accessibilityservice.AccessibilityService"/>
        </intent-filter>
        <meta-data android:name="android.accessibilityservice"/>
        <meta-data android:resource="@xml/accessibilityservice"/>
</service>

accessiblityservice.xml:

<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
xmlns:tools="http://schemas.android.com/tools"
android:accessibilityEventTypes="typeWindowStateChanged"
android:accessibilityFeedbackType="feedbackGeneric"
android:accessibilityFlags="flagIncludeNotImportantViews"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:ignore="UnusedAttribute"/>

Can some one tell me where I'm wrong ?


Solution

  • I found the mistake by myself. In the manifest.xml the meta-data tag should be on a single line, like below:

    <activity>
    ...
    </activity>
    <service android:name="com.myCompany.app.MyService"
             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/accessibilityservice"/>
    </service>