joakim0112
joakim0112

Reputation: 33

BroadcastReceiver not handling BOOT_COMPLETED

Here's my AndroidManifest.xml:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application>
    <receiver android:name=".MyBroadcastReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>

Here's my class MyBroadcastReceiver.java:

public class MyBroadcastReceiver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
        Log.d("TAG", "this is onReceive");

I'm using Android Studio 1.4 on Windows with the emulator. I'm not getting anything in my log.

Upvotes: 0

Views: 313

Answers (2)

kandroidj
kandroidj

Reputation: 13932

if you want to send a broadcast to your application from adb:

 adb shell am broadcast -a android.intent.action.BOOT_COMPLETED

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1007554

I just press play in android studio and expect my broadcast to work. This is wrong?

Yes, this is wrong.

First, Android Studio will only run an activity, specifically a launcher activity. Android Studio will not, on its own, send broadcasts.

Second, android.intent.action.BOOT_COMPLETED is broadcast when a device or emulator has rebooted (or is powered on from having been completely off). Running an app in Android Studio does not reboot a device or emulator. Running an app in Android Studio can boot an emulator, however your app will not be installed on the emulator until after that boot process has occurred and the BOOT_COMPLETED broadcast has been sent.

Upvotes: 0

Related Questions