Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessibilityservice not working via Notifications

I am playing around with an Accessibilityservice. I know how to read data from the notifications and I also know how to print the typed text into logcat.

Problem When I get e WhatsApp message from a friend I open that message via notifications. (see pic below) After that I can type any text in the chat but I don't get an output in logcat. When I open the whatsapp app normaly everything I type in the chat is visible in logcat.

Why is the data not logged, when I open the message via notifications?

enter image description here

Service

public class MyAccessibilityService2 extends AccessibilityService {

    protected void onServiceConnected() {
        AccessibilityServiceInfo info = new AccessibilityServiceInfo();
        info.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED | AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED;
        info.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK;
        info.notificationTimeout = 100;
        setServiceInfo(info);
    }

    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
        if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
            Log.d("Notification","Recieved event");
            Parcelable data = event.getParcelableData();
            if (data instanceof Notification) {
                Log.d("Notification","Recieved notification");
                Notification notification = (Notification) data;
                Log.d("Notification","ticker: " + notification.tickerText);
                Log.d("Notification","icon: " + notification.icon);
                Log.d("Notification", "notification: "+ event.getText());
                Log.d("Notification", "text: "+ notification.extras.getCharSequence(Notification.EXTRA_TEXT).toString());
            }
        }else if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
            Log.d("TEST", "HELLO");
            
        }else if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED) {
            Log.d("Text: ", "-> "+event.getText().toString());
        }
    }

    @Override
    public void onInterrupt() {
        // TODO Auto-generated method stub
    }
    
}

Manifest

<service
    android:name=".MyAccessibilityService2"
    android:enabled="true"
    android:exported="true"
    android:accessibilityFeedbackType="feedbackGeneric"
    android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
    <intent-filter>
        <action android:name="android.accessibilityservice.AccessibilityService" />
    </intent-filter>
</service>

Output when I open an app normaly

2020-07-17 14:24:59.782 9589-9589/com.android.rechner D/Text:: -> [T]
2020-07-17 14:25:00.046 9589-9589/com.android.rechner D/Text:: -> [Te]
2020-07-17 14:25:00.295 9589-9589/com.android.rechner D/Text:: -> [Tes]
2020-07-17 14:25:00.443 9589-9589/com.android.rechner D/Text:: -> [Test]
2020-07-17 14:25:00.958 9589-9589/com.android.rechner D/Text:: -> [Testm]
2020-07-17 14:25:01.155 9589-9589/com.android.rechner D/Text:: -> [Testme]
2020-07-17 14:25:01.381 9589-9589/com.android.rechner D/Text:: -> [Testmes]
2020-07-17 14:25:01.525 9589-9589/com.android.rechner D/Text:: -> [Testmess]
2020-07-17 14:25:01.740 9589-9589/com.android.rechner D/Text:: -> [Testmessa]
2020-07-17 14:25:01.858 9589-9589/com.android.rechner D/Text:: -> [Testmessag]
2020-07-17 14:25:01.959 9589-9589/com.android.rechner D/Text:: -> [Testmessage]

Output when I open an app by notification

There is no output in logcat :-(

Output from received notification

2020-07-17 14:27:36.272 9589-9589/com.android.rechner D/Notification: Recieved event
2020-07-17 14:27:36.273 9589-9589/com.android.rechner D/Notification: Recieved notification
2020-07-17 14:27:36.273 9589-9589/com.android.rechner D/Notification: ticker: Nachricht von Mami
2020-07-17 14:27:36.273 9589-9589/com.android.rechner D/Notification: icon: 2131231578
2020-07-17 14:27:36.273 9589-9589/com.android.rechner D/Notification: notification: [Nachricht von Patrick]
2020-07-17 14:27:36.276 9589-9589/com.android.rechner D/Notification: text: Test🤗
like image 866
MSeiz5 Avatar asked Jul 17 '20 12:07

MSeiz5


1 Answers

I tried your code and it works fine for me, the only problem I see in your code is that I cannot see the service_config set for your AccessibilityService in your Android Manifest. It should look something like this:

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

And your service_config should look like this:

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/accessibility_service_description"
android:packageNames="com.example.android.apis"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFlags="flagDefault"
android:accessibilityFeedbackType="feedbackSpoken"
android:notificationTimeout="100"
android:canRetrieveWindowContent="true"
android:settingsActivity="com.example.android.accessibility.ServiceSettingsActivity"/>

For more info refer to this page.

like image 176
cdevansh Avatar answered Nov 17 '22 15:11

cdevansh