尝试让我的应用点击某些应用上的正确位置。我使用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);
}
}
答案 0 :(得分:0)
找到类似的方式:
try {
dataOutputStream.writeBytes(command + "\n");
dataOutputStream.flush();
} catch (IOException e) {
e.printStackTrace();
}
其中“命令”某些命令带有“su”preveosly