Android accessibility service

大兔子大兔子 提交于 2019-11-29 07:57:37

I added a meta data element inside the service tag

<meta-data android:name="android.accessibilityservice" android:resource="@xml/accessibilityservice" />

And in the xml resources file I have

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
                       android:accessibilityEventTypes="typeNotificationStateChanged"
                       android:accessibilityFeedbackType="feedbackAllMask"
                       android:notificationTimeout="100" />

Accessibility Service is overkill for your purposes, you should use NotificationListenerService. The NotificationListenerService is much easier to implement and safer for users (privacy reasons).

One other way to configure the accessibility service is to Override the OnServiceConnected() method of your AccessibilityService from java code.

@Override
  protected void onServiceConnected() {
    AccessibilityServiceInfo info = getServiceInfo();
    info.packageNames = new String[]
        {
            "com.packagename1","com.packagename2"
        };
    info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;

    this.setServiceInfo(info);
  }

Reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!