Using java.awt.robot on Android app service

641 views Asked by At

I'm trying to use java.awt.Robot on android application with this code

Robot robot = null;
try {
    robot = new Robot();
} catch (AWTException e) {
    e.printStackTrace();
}

// Simulate a key press
robot.keyPress(KeyEvent.KEYCODE_A);
robot.keyRelease(KeyEvent.KEYCODE_A);

By default, It seems the

import java.awt.Robot;

is not available on Android SDK. So to do that I tried to import the .jar downloaded from http://www.java2s.com/Code/Jar/j/Downloadjavartjarstubs150jar.htm called

java-rt-jar-stubs-1.5.0.jar

But when I run the application on that line of code

robot = new Robot();

I get this Exception

java.lang.VerifyError: Verifier rejected class java.awt.Robot due to bad method void java.awt.Robot.<init>(java.awt.GraphicsDevice) (declaration of 'java.awt.Robot' appears in /data/app/com.example.myapp-1/split_lib_dependencies_apk.apk)

So I'm starting to think that maybe I can't use Java.awt.Robot even if I import the jar as a dependence of application.

As you can see from code, I need from my Application (in particular from my intent) to emulate keyboard input and write in every input text.

So I need to send text to input focused as emulated keyboard press.

Any ideas?

P.S.: I also tried to use this

Instrumentation m_Instrumentation = new Instrumentation();
m_Instrumentation.sendKeyDownUpSync( KeyEvent.KEYCODE_B );

whit permission

<permission android:name="android.permission.INJECT_EVENTS" />

but apparently it can not be used from third party application but only from verified Google Apps because I get this exception

java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
0

There are 0 answers