怎么在应用运行adb命令

2024-11-26 06:49:15
推荐回答(3个)
回答1:

在Android中,除了从界面上启动程序之外,还可以从命令行启动程序,使用的是命令行工具am.
usage: am [subcommand] [options]
start an Activity: am start [-D]
-D: enable debugging
send a broadcast Intent: am broadcast
start an Instrumentation: am instrument [flags]
-r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT)
-e : set argument to
-p : write profiling data to
-w: wait for instrumentation to finish before returning
start profiling: am profile start
stop profiling: am profile stop
specifications include these flags:
[-a ] [-d ] [-t ]
[-c [-c ] ...]
[-e|--es ...]
[--ez ...]
[-e|--ei ...]
[-n ] [-f ] []
启动的方法为:
$ adb shell
$ am start -n {包(package)名}/{包名}.{活动(activity)名称}

回答2:

关注。在cmd中执行adb shell后就进入了设备控制了,这里用bat肯定是不行的

回答3:

参考下这个/* * 清除缓存 */ public static void cleanCache(String appPackageName) { Process process = null; DataOutputStream os = null; String command = ""; try { process = Runtime.getRuntime().exec("su"); os = new DataOutputStream(process.getOutputStream()); command = "rm -r /data/data/" + appPackageName + "/cache \n"; os.writeBytes(command); os.flush(); os.close(); process.waitFor(); process.destroy(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }