如何将BOOT_COMPLETED广播仅发送到您的应用

时间:2015-09-22 13:35:18

标签: android shell

这是我一直试图将BOOT_COMPLETED广播发送到我的应用程序的唯一目的:

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -p my.package.name 

它给了我这个错误

Error: Unknown option: -p Broadcasting: null
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.content.Intent.writeToParcel(android.os.Parcel, int)' on a null object reference
at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:2929)
at com.android.commands.am.Am.sendBroadcast(Am.java:897)
at com.android.commands.am.Am.onRun(Am.java:321)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
at com.android.commands.am.Am.main(Am.java:102)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:255)

1 个答案:

答案 0 :(得分:2)

事实证明,为了向您的应用发送广播,您需要做的只是最后添加包。

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED my.package.name