0

I want to input "enter" key event programmatically from within my app.

I have tried it using abd shell command as well as using AccessibilityService, but found no luck in it.

Similar question was asked here as well

Below is my code which I used to execute adb shell command :

try {
    Runtime runtime = Runtime.getRuntime();

    Process p = runtime.exec("input keyevent 66");

    BufferedReader standardIn = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader errorIn = new BufferedReader(new InputStreamReader(p.getErrorStream()));

    String output = "";
    String line;
    while ((line = standardIn.readLine()) != null) {
        output += line + "\n";
    }
    while ((line = errorIn.readLine()) != null) {
        output += line + "\n";
    }

    Log.d("output", "" + output);
} catch (IOException e) {
    e.printStackTrace();
}

I am getting the following output :

sh: resetreason: can't execute: Permission denied

Someone please help me out.

If anyone knows how to achieve it using AccessibilityService as well, please let me know.

Thanks in advance!

Community
  • 1
  • 1
Wazz
  • 1
  • 1

1 Answers1

-1

Add this <uses-permission android:name="android.permission.ACCESS_SUPERUSER" /> permission & Try again .

Don Chakkappan
  • 7,397
  • 5
  • 44
  • 59