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);
参考