好吧,我搜索了很多.人们说我需要关闭模拟器的窗口来关闭它.但是,我需要重新启动模拟器赶上ACTION_BOOT_COMPLETEd我的BroadcastReceiver.
我怎样才能做到这一点?
小智 35
您可以使用adb中的以下命令:
adb shell am activity/service/broadcast -a ACTION -c CATEGORY -n NAME
Run Code Online (Sandbox Code Playgroud)
例如:
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n package_name/class_name
Run Code Online (Sandbox Code Playgroud)
请注意,类名和包名需要在Manifest中定义.
这将生成您想要的Intent,仅指向您想要的组件(否则您的系统将疯狂发送BOOT_COMPLETED ...)
Boo*_*ger 31
或者另一种方式(也来自命令行):
adb shell stop
adb shell start
Run Code Online (Sandbox Code Playgroud)
要模拟广播操作,您可以通过adb连接到模拟器/设备并打开shell:
adb shell
Run Code Online (Sandbox Code Playgroud)
然后,您可以广播要测试的操作:
am broadcast -a android.intent.action.BOOT_COMPLETED
Run Code Online (Sandbox Code Playgroud)
请注意,在最新的Android版本中,广播*android.intent.action.BOOT_COMPLETED*操作实际上会重启您的模拟器/设备.
首先,确保从模拟器中启用USB调试:
点击:
从命令行:
adb -e reboot
Run Code Online (Sandbox Code Playgroud)
编辑:
这肯定不起作用......很奇怪.我测试了它,无法重启模拟器.它只是挂起.