Android accessibility service not connected after

2019-03-31 04:20发布

I have this application running on adnroid devices. I need to react on WhatsApp notification (since I'm not aware of any other way) and make my application notify the user about new message. Our users are people with disabilities, so we need to provide somewhat simplier interface. In order to get the notification I created the accessibility service with "com.whatsapp" package filter. Everything works great until we reinstall our application. After reinstall we have to bind the service manually again (which is very problematic). Any help would be greatly appreciated!

This is the "onAccessibilityEvent" code:

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {

    Log.d(TAG, "NotificationService event");

    if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {

        String packageName = event.getPackageName().toString();

        if(packageName.equals("com.whatsapp")){
            // do some logic;
        }

// Utils.showLargeToast(getApplicationContext(), "New WhatsApp message"); } }

accessibilty_service_config

android:packageNames="@null"
android:accessibilityEventTypes="typeNotificationStateChanged"
android:accessibilityFlags="flagDefault"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="100"
android:canRetrieveWindowContent="false"
android:description="@string/description_that_shows_on_the_accessibility_page" />

and manifest part

     android:name=".NotificationService"
        android:enabled="true"
        android:exported="false"
        android:label="WhatsApp Monitor Service">

        <intent-filter>
            <action android:name="android.accessibilityservice.AccessibilityService" />
        </intent-filter>

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

Thanks in advance!

0条回答
登录 后发表回答