Accessibility Service description
Asked Answered
G

1

11

I wrote a very simple accessibilityService and i am trying to have the description of the service show up in Settings/accessibility/my app. Below is all my code which should set the description to "Hello!" but the settings still shows "no description available"

enter image description here

my service:

public class IdleService extends AccessibilityService{

    int interval = 100;
    int maxIdleTime = 20000;
    int idleTime = 0;
    Handler mHandler;
    String cProcess;

    @Override
    public void onServiceConnected(){

        mHandler = new Handler();

        AccessibilityServiceInfo info = new AccessibilityServiceInfo();
        // we are interested in all types of accessibility events
        info.describeContents();
        info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
        info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
        // we want to receive events in a certain interval
        info.notificationTimeout = interval;

        setServiceInfo(info);

        Log.e("IdleService", " idle service connected!");
        statusChecker.run();
    }

    @Override
    public void onAccessibilityEvent(AccessibilityEvent arg0) 
    {
        // TODO Auto-generated method stub
        Log.v("IdleService", "reseting idle time");
        idleTime = 0;
    }

    @Override
    public void onInterrupt() 
    {
        // TODO Auto-generated method stub
        Log.v("IdleService", "INTERUPTED");
    }

    public void setMaxIdleTimeInSeconds(int time)
    {

        maxIdleTime = time *1000;
    }


    Runnable statusChecker = new Runnable() 
    {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            ActivityManager am = (ActivityManager) getApplicationContext()
                    .getSystemService(Context.ACTIVITY_SERVICE);

            List<ActivityManager.RunningTaskInfo> processList = am
                    .getRunningTasks(5);

            cProcess = processList.get(0).baseActivity.getPackageName();

            Log.v("IdleService", "Current PackageName:"+cProcess);
            cProcess = processList.get(0).baseActivity.getClassName();

            Log.v("IdleService", "Current ClassName:"+cProcess);
            idleTime +=100;
            Log.v("IdleService", "TICK TOCK, user Idle for:"+idleTime);
            if(idleTime>=maxIdleTime)
            {
                Log.v("IdleService", "we timed out do to inactivity");
                //mHandler.postDelayed(statusChecker, interval);
                //stopSelf();
            }else{


            }
            mHandler.postDelayed(statusChecker, interval);
        }


    };
}

in my manifest i have this for the service:

<service android:name="com.myPackage.IdleService"
                android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
                    <meta-data
                    android:name="android.accessibilityservice"
                    android:resource="@xml/accessibility_service_config" />
                    <intent-filter>
                        <action android:name="android.accessibilityservice.AccessibilityService" />
                    </intent-filter>

                </service>

and in my res/xml i have an accessibility_service_config.xml file:

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:description="@string/accessibility_service_description"

    android:settingsActivity="com.example.android.accessibility.ServiceSettingsActivity"
/>

and finally in my res/values/ i have strings.xml which looks like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="accessibility_service_description">Hello!</string>
</resources>
Geraldina answered 9/10, 2013 at 13:56 Comment(1)
I know it's a but late but I believe I'm facing the exact same problem - How did you manage to solve this issue?Groyne
P
8

I ran into this same issue and eventually got it to work. I know the service itself includes the permission but you need to add the BIND_ACCESSIBILITY_SERVICE permission to the manifest as well.

<manifest ...>
    ...
    <uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
    ...
</manifest>

The <meta-data> for the service must be named android.accessibilityservice which you have so that's good.

Finally, I had to push the apk to my device and then restart it for the changes to take.

NOTE: adding the description attribute in the <service> element in the manifest does not affect the service description shown in system settings.

Pheni answered 9/7, 2015 at 12:25 Comment(2)
Thank you for the NOTE. I added the description to the service and I could not find why it was not appearing in the Settings.Relator
To get the description to appear, the the android:description attribute must be set in the accessibility_service_config.xml file, not the manifest as I first tried.Delozier

© 2022 - 2024 — McMap. All rights reserved.