您的位置:首页 > 移动开发

利用adb 命令回到手机端某个app的页面

2016-06-02 15:02 387 查看
利用adb 命令回到手机端某个app的页面,而不用点击本app图标

//需要执行的adb命令
String[] cmdStart = new String[] { "su",
"am start -n com.bpt.activity/com.bpt.activity.AcMain" };
try {
//执行adb 命令
CMDUtil.execShellCMD(cmdStart, 1);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}


执行命令的工具方法

public static void execShellCMD(String[] s, int execType) throws IOException,InterruptedException {
if (s.length != 0) {
Process p = Runtime.getRuntime().exec(s[0]);
// PROBLEM: only first cmd in the array can be implemented, the other can not be implemented(or we can't see)
if (s.length > 1) {
OutputStream outputStream = p.getOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
int i = 1;
dataOutputStream.writeBytes(s[1]);
dataOutputStream.flush();
dataOutputStream.close();
outputStream.close();
}
switch (execType) {
case 1:
p.waitFor();
break;
default:
p.waitFor();
break;
}
}
}


这个命令是在控制台连接手机

1.进入控制台


2.进入adb shell


3.在进入su



4.输入命令



这里就已经可以看到手机 上已经打开 Bpt 这个app的AcMain的页面

这个命令的格式:

am start -n app的包名/包名+类名

app的包名在项目的AndroidManifest.xml 文件中 可以看到 package=”com.bpt” 这个是这个项目的唯一标示。

好记性不如烂笔头

—–有信仰的小马
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  手机 app