How to Test Boot_Completed Broadcast Receiver in Emulator

How To Test BOOT_COMPLETED Broadcast Receiver In Emulator

There is no Power Button in Emulator like Devices have,So

To stop an emulator instance, just close the emulator's window.

And To Start/Restart it Start from AVD Manager of Eclipse and Your BroadcastReceiver with BOOT_COMPLETE action will get called for sure

You can start AVD another way also, From CMD go to Tools of AndroidSDK and give this commmand E:\android-sdk-windows\tools>emulator -avd AVDNAMEHERE

To Send Broadcast from CMD you can use this Command.

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


Read more about Android Emulator : Android Emulator and Using Emulator

how to catch the system broadcast BOOT_COMPLETED, my program just doesn't work?

Well I tried this and it Works for me,

public class Autostart extends BroadcastReceiver 
{
public void onReceive(Context arg0, Intent arg1)
{
Log.i("Autostart", "**********started************");
}
}

AndroidManifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pack.saltriver" android:versionCode="1" android:versionName="1.0"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">

<application android:icon="@drawable/icon" android:label="@string/app_name">

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

Debug android.intent.action.BOOT_COMPLETED

Use sendBroadcast() to send broadcast manually

Add some action ("NameofAction") to the receiver in the manifest and then manually use sendBroadcast(new Intent("NameofAction")) with the name you specified in the receiver element in the manifest.

and in onReceive() check for the action ("NameofAction").

How to debug BOOT_COMPLETE broadcast receiver's Force Close crashes?

check your Intent's actions and bundles you are recieving ,they may null and can be a null pointer exception.

Receiver on BOOT_COMPLETED not fired

I had to go to Settings/ Applications/ MyApp and enable autostart. So it's not a problem with my code. It's a security issue that some phones have like Xiaomi Redmi phones

How to reboot emulator to test ACTION_BOOT_COMPLETED?

You can use the following command from adb:

adb shell am activity/service/broadcast -a ACTION -c CATEGORY -n NAME

for example:

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n package_name/class_name

Note that class name and package names need to be as defined in the Manifest.

This will generate the Intent you want , directed only to the component you want (otherwise you system will go crazy with BOOT_COMPLETED sent...)

BOOT_COMPLETED isn't received by my physical phone Asus

There's an Auto-start Manager application which was denying my app to run at startup.

Asus Auto-start Manager

Now my application works well at start.

Thanks @Arseny Levin for the hint.



Related Topics



Leave a reply



Submit