Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessibility Service description

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>
like image 671
erik Avatar asked Oct 09 '13 13:10

erik


People also ask

What is an accessibility service?

An Accessibility Service assists users with disabilities in using Android devices and apps. It is a long-running privileged service that helps users process information on the screen and lets them to interact meaningfully with a device.

What is the meaning of accessibility in phone?

Android accessibility features allow users to customize their device by modifying accessibility settings or apps to improve their experience.

How do I turn off accessibility on Android?

Open your Android device's Settings app . Select Accessibility. Switch Access. At the top, select the On/Off switch.


1 Answers

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.

like image 102
kpninja12 Avatar answered Oct 03 '22 15:10

kpninja12