Tar Tar - 1 year ago 85
Android Question

In order to catch BOOT_COMPLETED, is it enough just to register the BroadcastReceiver in the `AndroidManifest.xml`?

In order to catch

events, is it enough just to register the
in the
? like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<!-- ... stuff ... -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- ... stuff ... -->
<application ...>
<!-- ... stuff ... -->
<receiver android:name=".bgServices.MyBootBroadcastReceiver">
<!-- ... stuff ... -->


package com.myDomain.myApp.bgServices;

// imports ...

public class MyBootBroadcastReceiver extends BroadcastReceiver {

public void onReceive(Context context, Intent intent) {
Log.d("my-log", "MyBootBroadcastReceiver.onReceive()");
Toast.makeText(context, "YEAY!", Toast.LENGTH_LONG).show();

I'm asking because I'm sending:

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -n com.myDomain.myApp/.bgServices.MyBootBroadcastReceiver

But nothing happens.

(and I run the app, not just pushing it to the device)

Answer Source

Add the following IntentFilters to your BroadcastReceiver:

<receiver android:name=".bgServices.MyBootBroadcastReceiver" >
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="android.intent.action.QUICKBOOT_POWERON" />

Although android.intent.action.BOOT_COMPLETED should be enough, it seems some devices require android.intent.action.QUICKBOOT_POWERON also.

For more information, you should take a look at the developer's guide on Intents and IntentFilters.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download