【问题标题】:dont work "input tap x y" with external app不要使用外部应用程序“输入点击 x y”
【发布时间】:2016-09-15 13:40:52
【问题描述】:

尝试让我的应用点击某些应用上的正确位置。我将 Runtime.getRuntime().exec() 与“input tap x y”adb shell 命令一起使用,但它仅适用于我的活动。我该怎么做才能让它发挥作用?

Thread r;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button BtnStart = (Button) findViewById(R.id.btnStart);

    try {
        Runtime.getRuntime().exec("su");
    } catch (IOException e) {
        e.printStackTrace();
    }

    r = new Thread() {
        @Override
        public void run() {
            try{
                synchronized (this){
                    sleep(10000);
                }
            } catch (InterruptedException e){

            }
            try {
                Runtime.getRuntime().exec("input tap 120 1050");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    };
    View.OnClickListener StartClick = new View.OnClickListener(){
        @Override
        public void onClick(View v) {
            StartApp("some.app.here");
            r.start();
        }
    };
    BtnStart.setOnClickListener(StartClick);

}

public void StartApp(String AppName){
    Intent LaunchApp = getPackageManager().getLaunchIntentForPackage(AppName);
    if (LaunchApp != null) {
        startActivity(LaunchApp);
    }
}

【问题讨论】:

    标签: android android-activity input su


    【解决方案1】:

    找到类似的方法:

     try {
                   dataOutputStream.writeBytes(command + "\n");
                   dataOutputStream.flush();
                } catch (IOException e) {
                    e.printStackTrace();
                }
    

    在哪里用“su”预先“命令”一些命令

    【讨论】:

      猜你喜欢
      • 2019-02-14
      • 1970-01-01
      • 2012-05-24
      • 1970-01-01
      • 1970-01-01
      • 2018-11-10
      • 2017-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多