Reputation: 2253
I want to check the BROADCAST RECEIVER with Action BOOT_COMPLETED in the emulator.
This my code
public class AutoRunService extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Toast.makeText(UApplication.getInstance(), "Application is ready to open ", Toast.LENGTH_SHORT).show();
myFunciton(context);
}
}
public void myFunciton(Context context) {
}
}
<receiver
android:name=".AutoRunService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
I'm using windows 10 and genymotion emulator. Is there any way to check that broadcast receiver in emulator ? How can i restart emulator to check that receiver ? is there any direct command?
Thanks in advance.
Upvotes: 5
Views: 5307
Reputation: 1396
Just put a debug log inside your onRecieve() callback as follows :
public class AutoRunService extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Log.d("Boot", "completed"); // log to make sure that boot completed action is received
}
}
And to restart the emulator, refer the following answer :
How to reboot emulator to test ACTION_BOOT_COMPLETED?
Upvotes: 1
Reputation: 4530
Go to adb tools -> goto adb shell and use following command
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -p com.example.package
Upvotes: 3