asmaldone2
asmaldone2

Reputation: 55

Why is my accessibility service not being started?

I have created an accessibility service to see if I can perform gesture navigation with my app. The problem is my accessibility service is not being started at all. A possible hint into this problem is that I do not see my app in the accessibility portion of the settings page. I have added the proper permission in my Manifest file, and do not see where I am going wrong.

Here is my Manifest file:

<service 
            android:name=".AccessibilityService"
            android:enabled="true"
            android:exported="true"
            android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
            android:label="@string/accessibility_service_label">
            <meta-data
                android:name="android.accessibilityservice"
                android:resource="@xml/accessibility_service_config" />
</service>

Here is my accessibility service configuration XML file:

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityEventTypes="typeAllMask"
    android:accessibilityFeedbackType="feedbackAllMask"
    android:accessibilityFlags="flagDefault"
    android:canRequestEnhancedWebAccessibility="true"
    android:canRetrieveWindowContent="true"
    android:packageNames="com.example.adtry3"
    android:canRequestTouchExplorationMode="true"
    android:settingsActivity="com.example.adtry3.MainActivity" />

Here is my accessibility service class:

package com.example.adtry3;

import android.accessibilityservice.AccessibilityServiceInfo;
import android.annotation.TargetApi;
import android.os.Build;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import androidx.annotation.RequiresApi;
import java.util.List;



@TargetApi(Build.VERSION_CODES.DONUT)
public class AccessibilityService extends android.accessibilityservice.AccessibilityService {


    @Override
    public void onServiceConnected(){           
        System.out.println("ONSERVICECONNECTED");
        
        AccessibilityServiceInfo info = getServiceInfo();
        
        info.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK;
        info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
        info.packageNames = new String[] {"com.example.adtry3"};
        info.notificationTimeout = 100;
        
        setServiceInfo(info);
    }
    
    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) { 
       System.out.println("Testing");
    }



    @Override
    public void onInterrupt() {

    }


    public void onUnbind(){         //service is being terminated, do final one-time operations here

    }

}

Lastly, this is the OnCreate method of my MainActivity.java:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
        startActivityForResult(intent, 0);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
}

If I am missing something, or if you know what is going on, please let me know. I have search on other StackOverflow answers and have had no luck. Thank you.

Upvotes: 1

Views: 1305

Answers (1)

snachmsm
snachmsm

Reputation: 19273

add this filter to your <service declaration in manifest

<intent-filter>
    <action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>

also you may have to add these lines in your service config xml

android:description="@string/accessibility_service_desc"
android:notificationTimeout="25"

Upvotes: 1

Related Questions