Question

I am trying to start my accessibility service on android 4.0.4 but not able to start. it works fine on 2.3.3. But no luck for updated version. I have tried this suggestion.AccessibilityService is started but does not receive AccessibilityEvents on JellyBean Here is my code .

public class NotificationService extends AccessibilityService {

static final String TAG = "NotificationService";


private String getEventType(AccessibilityEvent event) {
    switch (event.getEventType()) {
        case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:
            return "TYPE_NOTIFICATION_STATE_CHANGED";
        case AccessibilityEvent.TYPE_VIEW_CLICKED:
            return "TYPE_VIEW_CLICKED";
        case AccessibilityEvent.TYPE_VIEW_FOCUSED:
            return "TYPE_VIEW_FOCUSED";
        case AccessibilityEvent.TYPE_VIEW_LONG_CLICKED:
            return "TYPE_VIEW_LONG_CLICKED";
        case AccessibilityEvent.TYPE_VIEW_SELECTED:
            return "TYPE_VIEW_SELECTED";
        case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
            return "TYPE_WINDOW_STATE_CHANGED";
        case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED:
            return "TYPE_VIEW_TEXT_CHANGED";
    }
    return "default";
}

private String getEventText(AccessibilityEvent event) {
    StringBuilder sb = new StringBuilder();
    for (CharSequence s : event.getText()) {
        sb.append(s);
    }
    return sb.toString();
}




  @Override
  public void onAccessibilityEvent(AccessibilityEvent event) {
    Toast.makeText(this, "Got event from " + event.getPackageName(), Toast.LENGTH_SHORT)
            .show();
    //Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE);
   // v.vibrate(new long[] { 0, 250, 250, 250, 250, 250, 250, 250, 250 }, -1);

    Log.v(TAG, String.format(
            " onAccessibilityEvent: [type] %s [class] %s [package] %s [time] %s [text] %s",
            getEventType(event), event.getClassName(), event.getPackageName(),
            event.getEventTime(), getEventText(event)));

  }

  @Override
  public void onInterrupt() {Log.v(TAG, "onInterrupt"); }

  @Override
    protected void onServiceConnected() {
        super.onServiceConnected();
        Log.v(TAG, "onServiceConnected");
        AccessibilityServiceInfo info = new AccessibilityServiceInfo();
        info.flags = AccessibilityServiceInfo.DEFAULT;
        info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
        info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
        setServiceInfo(info);
    }

}

And Manifest is:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.watchservice"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

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


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.watchservice.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name=".NotificationService" android:enabled="true" 
            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>
    </application>

</manifest>

suggest me , where am i going wrong ?

Was it helpful?

Solution

I added a meta tag in manifest by mistake, which is basically for higher version then ICS.After removing the meta tag from android 4.0.4 application, it works.

if i have this tag in Manifest file it does not work, as suggested it was for newer version of android.

<meta-data android:name="android.accessibilityservice" android:resource="@xml/accessibilityservice" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top