jiraya85
jiraya85

Reputation: 428

Android BootReceiver does not work

I'm trying to listen for reboot event.

I'v created the following class:

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

public class OnBootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("MYBOOTRECEIVER", "HELLO!");
    }
}

and then in the manifest file I've putted the following xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mypackage"
    android:installLocation="internalOnly"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="3"
        android:targetSdkVersion="8" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <application android:label="@string/app_name" >
        <receiver android:name=".OnBootReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
                <category android:name="android.intent.category.HOME" />
            </intent-filter>
        </receiver>
    </application>
</manifest>

However, after I've installed this app and rebooted the device, nothing happens. (I'm using a galaxy tab 8.9 with android 3.2 on it). As you can see from the manifest I've installed the app on internal memory (like suggested on similar questions here on stackoverflow) ... I've also putted a Quickboot_poweron action (to see if galaxy tab have similar behaviour of htc devices) ... but nothing. I hope that someone can help me!

Upvotes: 4

Views: 5741

Answers (2)

Hardik4560
Hardik4560

Reputation: 3220

The action mention in your manifest is correct except the category part, this can be exclude if you just want to receive for boot complete. And in Receiver file this will work fine, but you should always use an if-else statement to distinguish between actions received.

    if (action.equals(android.intent.action.BOOT_COMPLETED)) {
       Log.i("MYBOOTRECEIVER", "BOOT COMPLETED RECEIVED");
    }

Upvotes: 0

mah
mah

Reputation: 39807

The problem is that with Honeycomb and beyond, broadcast signals do not automatically start an application which has not been otherwise started. There is a flag that can be used to change this however the BOOT_COMPLETED broadcast does not carry that flag. You need to be installed on the system partition in order to overcome this nuance.

If you're not able to be installed on the system partition, you'll need to find some other way to be started -- either by convincing the user to start you manually, or having the user install a widget you provide, etc.

Upvotes: 1

Related Questions