2

I have a really simple problem which is driving me nuts. I am creating a BroadcastReceiver, declaring it on the manifest but it just wont run. I'm trying to make it trigger on device boot. Here's the code:

package com.vullnetdyla.bcreceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class Receiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("ftw", "It worked");
    }
}

And the manifest file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vullnetdyla.bcreceiver"
android:versionCode="1"
android:versionName="1.0">

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application android:label="@string/app_name"
    android:icon="@drawable/ic_launcher"
    android:theme="@style/AppTheme">

    <receiver android:name="com.vullnetdyla.bcreceiver.Receiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>

</application>

Volo
  • 28,673
  • 12
  • 97
  • 125
vullnetyy
  • 1,488
  • 13
  • 15
  • 1
    Is your debugger actually connected when this log message fires? Perhaps do something more obvious, initiate a notification. – Pork 'n' Bunny Aug 08 '12 at 13:28
  • As pork said... Show a toast instead... – AAnkit Aug 08 '12 at 13:31
  • How do I know if the debugger is connected? I receive all kinds of messages but when I filter them out using the tag: ftw, it doesn't show me any. Any clue as on how to make sure the Log thing works? Meanwhile I'll try to toast the message and see what happens – vullnetyy Aug 10 '12 at 16:49

1 Answers1

4

Do you have some Activity which user can launch?

If not this is your problem! Since android 3.1 after installation application (package to be more specific) is in stopped state and doesn't receive ANY broadcast. User have to launch it manually at lest once to make it work. See section "Launch controls on stopped applications" in release notes of Android 3.1.
See also flags FLAG_INCLUDE_STOPPED_PACKAGES, FLAG_EXCLUDE_STOPPED_PACKAGES.

Marek R
  • 32,568
  • 6
  • 55
  • 140
  • No I don't have an activity for this broadcast receiver. But by reading your link I'm now convinced that I should. I should make an activity which starts the whole thing. I'll try it and see what happens – vullnetyy Aug 17 '12 at 08:17
  • Nope. You need one activity which does nothing but user can launch it, so he will make your package started (not stopped). I usually do AboutActivity in such cases. – Marek R Aug 17 '12 at 08:54