I'm trying to get an Andriod App that will start up after the phone has been rebooted. I looked how to do this on stackoverflow here and here, and on various other sites here, here and of course here.
No matter what I do I can not get my broadcast receiver to pick up the event.
Here is my BroadcastReceiver code. BTW I've also tried to get it to pick up ACTION_AIRPLANE_MODE_CHANGED events so I don't have to keep rebooting the phone. And No neither events are captured.
public class BootCompleteReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("BootCompleteReceiver", "Boot Completed Event Received");
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {//ACTION_REBOOT
Intent serviceIntent = new Intent(context, MainActivity.class);
context.startService(serviceIntent);
}
if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())) {
Log.i("BootCompleteReceiver", "Airplan mode changed");
Intent serviceIntent = new Intent(context, MainActivity.class);
context.startService(serviceIntent);
}
}
}
Here is the most complete part of my manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.co.jeeni.autosail"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="17" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:label="Tests for My App"
android:targetPackage="uk.co.jeeni" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="android.test.runner" />
<receiver android:name="uk.co.jeeni.android.broadcastReceivers.BootCompleteReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" >
</action>
</intent-filter>
</receiver>
<receiver android:name="uk.co.jeeni.android.broadcastReceivers.BootCompleteReceiver" >
<intent-filter>
<action android:name="android.content.Intent.ACTION_AIRPLANE_MODE_CHANGED" >
</action>
</intent-filter>
</receiver>
<activity
android:name="uk.co.jeeni.android.activity.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
.....
I'm not getting any errors, everything deploys to my phone OK, none of the log messages in the Receiver get called, and nothing happens when I change airplane mode, reboot my phone etc, and I've tried with only one <receiver> entry. I would try registering the receiver in code, but that only works when the application is already running, so defeats the purpose of running the app after a reboot.
Can anyone spot where I have gone wrong and what I need to do to fix it.