Android Key Logger with specific restrictions

For my Master Thesis, I am doing an Android app. I need to add a Key Logger to monitor user input text. I would like to monitor ONLY input text from an specific app (Whatsapp). For privacy reasons I don't want to record alphanumeric characters.

I would like to store just non alphanumeric characters (including backspaces).

For now, I have a Key Logger (MyAccessibilityService class) that store every character (with the DateTime) in Firebase, but I need to change my code.

Here is the code:

package com.example.appfirebase;

import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.view.accessibility.AccessibilityEvent;
import android.provider.Settings.Secure;

public class MyAccessibilityService extends AccessibilityService {

    DatabaseReference mRootReference;

    public void onAccessibilityEvent(AccessibilityEvent event) {

        mRootReference = FirebaseDatabase.getInstance().getReference();

        String id = Secure.getString(getBaseContext().getContentResolver(), Secure.ANDROID_ID);

        final int eventType = event.getEventType();
        String eventText = null;

        switch (eventType) {

            case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED:
                String dateTime =;
                eventText = dateTime + " --> Typed: ";

        eventText = eventText + event.getText();

        //print the typed text in the console. Or do anything you want here.
        System.out.println("ACCESSIBILITY SERVICE : " + eventText);


    public void onInterrupt() {

    public void onServiceConnected() {
        //configure our Accessibility service
        AccessibilityServiceInfo info = getServiceInfo();
        info.eventTypes = AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED;
        info.feedbackType = AccessibilityServiceInfo.FEEDBACK_SPOKEN;
        info.notificationTimeout = 100;


And this is the Manifest:

<service android:name=".MyAccessibilityService"
         <action android:name="android.accessibilityservice.AccessibilityService"/>

PS: I got this code from Android Key logger.