我们都知道用"adb install filename.apk"命令可以安装一个android程序,那你知道在安装后如何启动你的程序吗?
试试下面的命令吧。
adb shell am start
-
a android.intent.action.MAIN
-
c android.intent.category.LAUNCHER
-
n breakan.test
/
break
an.test.TestActivity
adb shell am start - a android.intent.action.MAIN - c android.intent.category.LAUNCHER - n breakan.test / break an.test.TestActivity
或简单一些。
adb shell am start
-
n breakan.test
/
breakan.test.TestActivity
adb shell am start - n breakan.test / breakan.test.TestActivity
其中"breakan.test/breakan.test.TestActivity"中的"breakan.test"是程序的包名,"TestActivity"是程序Activity类的类名。
我们来看下adb shell am命令的帮助。
usage: am [subcommand] [options]
start an Activity: am start [
-
D] [
-
W]
<
INTENT
>
-
D: enable debugging
-
W: wait
for
launch to complete
start a Service: am startservice
<
INTENT
>
send a broadcast Intent: am broadcast
<
INTENT
>
start an Instrumentation: am instrument [flags]
<
COMPONENT
>
-
r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT)
-
e
<
NAME
>
<
VALUE
>
: set argument
<
NAME
>
to
<
VALUE
>
-
p
<
FILE
>
: write profiling data to
<
FILE
>
-
w: wait
for
instrumentation to finish before returning
start profiling: am profile
<
PROCESS
>
start
<
FILE
>
stop profiling: am profile
<
PROCESS
>
stop
<
INTENT
>
specifications include these flags:
[
-
a
<
ACTION
>
] [
-
d
<
DATA_URI
>
] [
-
t
<
MIME_TYPE
>
]
[
-
c
<
CATEGORY
>
[
-
c
<
CATEGORY
>
] ...]
[
-
e
|--
es
<
EXTRA_KEY
>
<
EXTRA_STRING_VALUE
>
...]
[
--
esn
<
EXTRA_KEY
>
...]
[
--
ez
<
EXTRA_KEY
>
<
EXTRA_BOOLEAN_VALUE
>
...]
[
-
e
|--
ei
<
EXTRA_KEY
>
<
EXTRA_INT_VALUE
>
...]
[
-
n
<
COMPONENT
>
] [
-
f
<
FLAGS
>
]
[
--
grant
-
read
-
uri
-
permission] [
--
grant
-
write
-
uri
-
permission]
[
--
debug
-
log
-
resolution]
[
--
activity
-
brought
-
to
-
front] [
--
activity
-
clear
-
top]
[
--
activity
-
clear
-
when
-
task
-
reset] [
--
activity
-
exclude
-
from
-
recents]
[
--
activity
-
launched
-
from
-
history] [
--
activity
-
multiple
-
task]
[
--
activity
-
no
-
animation] [
--
activity
-
no
-
history]
[
--
activity
-
no
-
user
-
action] [
--
activity
-
previous
-
is
-
top]
[
--
activity
-
reorder
-
to
-
front] [
--
activity
-
reset
-
task
-
if
-
needed]
[
--
activity
-
single
-
top]
[
--
receiver
-
registered
-
only] [
--
receiver
-
replace
-
pending]
[
<
URI
>
]
启动的方法为
# am start -n 包(package)名/活动(activity)全路径
查看包中每个activity的全路径的方法:
方法A:
用apktool反编译apk,
打开AndroidManifest.xml找activity android:name,
例如:<activity android:label="@string/app_name" android:name="com.example.davicom_usb.USBMain">
方法B:
1、安装并启动“固件工具箱”
2、进入“App manager”,显示系统中所有安装程序,长按想通过命令行启动的程序。
3、弹出的窗口中选择"Advanced
Freeze",该程序所有的activity就会全部显示出来
activity有两种显示格式,一种直接显示全路径,另一种在括号里显示相对路径,相对路径加上包名即是全路径。
几个启动指定程序activity的例子
Music
和 Video(音乐和视频)的启动方法为:
#
am start -n com.android.music/com.android.music.MusicBrowserActivity
#
am start -n com.android.music/com.android.music.VideoBrowserActivity
#
am start -n com.android.music/com.android.music.MediaPlaybackActivity
Camera(照相机)的启动方法为:
#
am start -n com.android.camera/com.android.camera.Camera
Browser(浏览器)的启动方法为:
#
am start -n com.android.browser/com.android.browser.BrowserActivity
启动浏览器
:
am
start -a android.intent.action.VIEW -d
拨打电话
:
am
start -a android.intent.action.CALL -d tel:10086
启动
google map 直接定位到北京 :
am
start -a android.intent.action.VIEW geo:0,0?q=beijing
usage: am [subcommand] [options] start an Activity: am start [ - D] [ - W] < INTENT > - D: enable debugging - W: wait for launch to complete start a Service: am startservice < INTENT > send a broadcast Intent: am broadcast < INTENT > start an Instrumentation: am instrument [flags] < COMPONENT > - r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT) - e < NAME > < VALUE > : set argument < NAME > to < VALUE > - p < FILE > : write profiling data to < FILE > - w: wait for instrumentation to finish before returning start profiling: am profile < PROCESS > start < FILE > stop profiling: am profile < PROCESS > stop < INTENT > specifications include these flags: [ - a < ACTION > ] [ - d < DATA_URI > ] [ - t < MIME_TYPE > ] [ - c < CATEGORY > [ - c < CATEGORY > ] ...] [ - e |-- es < EXTRA_KEY > < EXTRA_STRING_VALUE > ...] [ -- esn < EXTRA_KEY > ...] [ -- ez < EXTRA_KEY > < EXTRA_BOOLEAN_VALUE > ...] [ - e |-- ei < EXTRA_KEY > < EXTRA_INT_VALUE > ...] [ - n < COMPONENT > ] [ - f < FLAGS > ] [ -- grant - read - uri - permission] [ -- grant - write - uri - permission] [ -- debug - log - resolution] [ -- activity - brought - to - front] [ -- activity - clear - top] [ -- activity - clear - when - task - reset] [ -- activity - exclude - from - recents] [ -- activity - launched - from - history] [ -- activity - multiple - task] [ -- activity - no - animation] [ -- activity - no - history] [ -- activity - no - user - action] [ -- activity - previous - is - top] [ -- activity - reorder - to - front] [ -- activity - reset - task - if - needed] [ -- activity - single - top] [ -- receiver - registered - only] [ -- receiver - replace - pending] [ < URI > ] 启动的方法为 # am start -n 包(package)名/活动(activity)全路径 查看包中每个activity的全路径的方法: 方法A: 用apktool反编译apk, 打开AndroidManifest.xml找activity android:name, 例如: 方法B: 1、安装并启动“固件工具箱” 2、进入“App manager”,显示系统中所有安装程序,长按想通过命令行启动的程序。 3、弹出的窗口中选择"Advanced Freeze",该程序所有的activity就会全部显示出来 activity有两种显示格式,一种直接显示全路径,另一种在括号里显示相对路径,相对路径加上包名即是全路径。 几个启动指定程序activity的例子 Music 和 Video(音乐和视频)的启动方法为: # am start -n com.android.music/com.android.music.MusicBrowserActivity # am start -n com.android.music/com.android.music.VideoBrowserActivity # am start -n com.android.music/com.android.music.MediaPlaybackActivity Camera(照相机)的启动方法为: # am start -n com.android.camera/com.android.camera.Camera Browser(浏览器)的启动方法为: # am start -n com.android.browser/com.android.browser.BrowserActivity 启动浏览器 : am start -a android.intent.action.VIEW -d 拨打电话 : am start -a android.intent.action.CALL -d tel:10086 启动 google map 直接定位到北京 : am start -a android.intent.action.VIEW geo:0,0?q=beijing
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/290900.html