adb命令启动某个action_adb命令启动service、Activity和发送Broadcast

adb shell am startservice com.bokezhi.test/.myService

二:启动Activity

adb shell am start com.bokezhi.test/.MainActivity

还可以带参数,我在Android 9.0测试无法启动。(具体可以参考Broadcast的,这个比较少用)

三:发送Broadcast

adb shell am broadcast 后面的参数有:

[-a ]

[-d ]

[-t ]

[-c [-c ] ...]

[-e|--es ...]

[--ez ...]

[-e|--ei ...]

[-n ]

[-f ] []

常用实例

# 广播1 不带参数

adb shell am broadcat -a com.125la.test

# 广播2 带String类型的参数

adb shell am broadcast -a com.125la.test --es test_string "this is test string"

# 广播3 带int类型的参数

adb shell am broadcast -a com.125la.test --ei test_int 100

# 广播4 带boolean类型的参数

adb shell am broadcast -a com.125la.test --ez test_boolean true

广播1

Intent intent= new Intent();

intent.setAction("com.125la.test");

sendBroadcast(intent);

广播2

--es 指后面跟String的参数Key和Value

Intent intent= new Intent();

intent.setAction("com.125la.test");

intent.putExtra("test_int", "this is test string");

sendBroadcast(intent);

广播3

--ei 指后面跟int的参数Key和Value

Intent intent= new Intent();

intent.setAction("com.125la.test");

intent.putExtra("test_int", 100);

sendBroadcast(intent);

广播4

--ez 指后面跟boolean的Key和Value

Intent intent= new Intent();

intent.setAction("com.125la.test");

intent.putExtra("test_boolean", true);

sendBroadcast(intent);

参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值