Android adb shell am broadcast: Bad component name
Asked Answered
T

4

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>
Tilda answered 2/3, 2011 at 17:49 Comment(0)
M
82

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

Mugwump answered 26/3, 2011 at 20:40 Comment(2)
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.Tilda
Is this now broken in Android 8/9?Domineca
E
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.

Effrontery answered 29/3, 2012 at 10:9 Comment(0)
T
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
Thaddeusthaddus answered 23/5, 2015 at 0:13 Comment(0)
J
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" />

Jalapa answered 10/11, 2017 at 22:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.