46

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>
altendky
  • 4,176
  • 4
  • 29
  • 39

4 Answers4

81

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 :)

Phil
  • 35,852
  • 23
  • 123
  • 164
lapis
  • 6,872
  • 4
  • 35
  • 40
  • 1
    *grrr* a dot delimited hierarchy with a random slash thrown in there! *boggle* regardless, i'm glad you found my post useful and were able to help me out too. thanks. – altendky Mar 27 '11 at 15:05
  • Is this now broken in Android 8/9? – Kenny Dec 18 '18 at 18:47
61

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.

Viet
  • 611
  • 5
  • 2
11

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
ejboy
  • 4,081
  • 5
  • 30
  • 32
2

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" />

foo
  • 574
  • 8
  • 13