I am trying to 'emulate' a reboot (or anything else with the adb shell am
) and am unable to figure out how to reference my component. Then again, maybe I don't even understand what is meant by a component. Below I first include a few example commands that don't work, then my manifest. Note that StartupReceiver is successfully called when the 'phone' boots. I just want to re-trigger it without a full reboot.
Failed ADB commands:
$ ./adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n net.fstab.checkit_android.StartupReceiver
<help snipped>
Error: Bad component name: net.fstab.checkit_android.StartupReceiver
$ ./adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n开发者_开发知识库 .StartupReceiver
<help snipped>
Error: Bad component name: .StartupReceiver
$ ./adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n StartupReceiver
<help snipped>
Error: Bad component name: StartupReceiver
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.fstab.checkit_android" android:installLocation="internalOnly"
android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".BaseActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="BasePreferences" />
<activity android:name="EditActivity" />
<receiver android:name="StartupReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<receiver android:name="NotificationReceiver">
<intent-filter>
<action android:name="net.fstab.checkit_android.NotificationReceiver" />
</intent-filter>
</receiver>
<service android:name="StartupService">
<intent-filter>
<action android:name="net.fstab.checkit_android.StartupService" />
</intent-filter>
</service>
</application>
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
</manifest>
You need to specify the package name before the class name (then you may write it without the package) like this:
./adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n net.fstab.checkit_android/.StartupReceiver
Practically it turns out that you just have to add a slash after the package name.
You helped me start, I helped you finish :)
Broadcast does not require specify any Receiver. This case, please just stroke
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED
Hope this help.
Some apps may misbehave if BOOT_COMPLETED is received twice, instead limit broadcast to your app only:
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -p com.example.package
Try
adb shell am broadcast \
-a android.intent.action.BOOT_COMPLETED \
-n net.fstab.checkit_android/.StartupReceiver
(note the -n net.fstab.checkit_android/.StartupReceiver) to aim at a specific receiver.
Also make sure your app uses permission to receive specific broadcast intents - in this case it would be
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
精彩评论