Android accessibility service

后端 未结 3 395
日久生厌
日久生厌 2020-12-18 10:01

I\'m trying to write a very basic android accessibility service that shows a message and vibrates when any notification is raised. I\'ve tried testing it by sending an email

相关标签:
3条回答
  • 2020-12-18 10:37

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

    0 讨论(0)
  • 2020-12-18 10:38

    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

    • https://developer.android.com/training/accessibility/service.html
    0 讨论(0)
  • 2020-12-18 10:41

    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" />
    
    0 讨论(0)
提交回复
热议问题