Android BootReceiver not working

I am trying to listen for a 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 put 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 installed this application and rebooted the device, nothing happens. (I use the Galaxy Tab 8.9 with Android 3.2 on it). As you can see from the manifest, I installed the application in internal memory (for example, suggested on similar issues here in stackoverflow) ... I also added the Quickboot_poweron action (to see if the galaxy tab has the same behavior for htc devices) ... but nothing. I hope someone can help me!

+4
source share
3 answers

I ran into the same problem earlier on a post 3.0 device.

Cause

Starting with 3.1, when applications are installed, they are β€œstopped” so that they cannot work until the user explicitly launches them. Pressing Force Stop will return them to this state.

as soon as the user starts the application for the first time (and does not disable Force it), everything behaves as before - the reboot will cause BOOT_COMPLETED broadcasts to be received, and so on. However, if the user installs the applications until they launch the application manually, no translations will be received.

Thus, in your case, you will need to create a launch activity and make sure that you run this launch activity at least once, after which you will begin to receive broadcast of boot events.

+8
source

The problem is that with Honeycomb and above, broadcast signals do not automatically launch an application that was not otherwise launched. There is a flag that can be used to change it, but the BOOT_COMPLETED broadcast does not carry this flag. You must be installed on the system partition to overcome this nuance.

If you cannot be installed in the system partition, you will need to find another way to start - either by convincing the user to start you manually, or if the user installs the widget that you provide, etc.

+1
source

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

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

All Articles