execute adb shell input swipe command from apk

后端 未结 2 802
故里飘歌
故里飘歌 2020-12-22 03:05

I am trying to execute swipe command from my Apk using

process = Runtime.getRuntime().exec(\"adb shell input swipe 250 300 -800 300\");

相关标签:
2条回答
  • 2020-12-22 03:50

    You can only execute /system/bin/input as the root or shell user; this will not work in an app. The command should not start with "adb shell" when running from the app.

    To run the command as root:

    Process su = null; 
    try { 
        su = Runtime.getRuntime().exec("su");
        su.getOutputStream().write("input swipe 250 300 -800 300\n".getBytes());
        su.getOutputStream().write("exit\n".getBytes());
        su.waitFor(); 
    } catch (Exception e) {
        e.printStackTrace();
    } finally { 
        if (su != null) { 
            su.destroy(); 
        } 
    }
    

    You should also check out third party libraries for handling su commands: https://android-arsenal.com/details/1/451

    0 讨论(0)
  • 2020-12-22 04:01

    You need to put INJECT_EVENTS permission in your manifest:

    
    
    uses-permission android:name="android.permission.INJECT_EVENTS"
    
    
    0 讨论(0)
提交回复
热议问题