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
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
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" />