I writed a small program to catch the system broadcast BOOT_COMPLETED
, but it just doesn\'t work:
package com.alex.app.testsysreboot;
import an
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>
You need to add
android:enabled="true"
android:exported="true"
AND
make sure that the app is not installed on the SD card - IIRC apps installed there don't receive that BOOT_COMPLETED
.
Another point is that devices with "Fast Boot" enabled (like several HTC devices) (sometimes?) don't send BOOT_COMPLETED
.
Since Android 3.1+ there is some more weirdness regarding BOOT_COMPLETED
relating to "very first start of an app" - see http://commonsware.com/blog/2011/07/13/boot-completed-regression-confirmed.html
A working sample project with source see https://github.com/commonsguy/cw-advandroid/tree/master/SystemEvents/OnBoot
From http://arthurfmay.blogspot.com/2011/06/broadcastreceiver-bootcompleted-and.html
So instead, from Eclipse I just went into the Android SDK and AVD Manager (under the Window Menu) and started the emulator from there. I did this of course after loading the app into the emulator. I start the emulator and my BroadcastReceiver on boot works just fine. There was no need to go to running the emulator at the command line.
Another working sample can be found here.