I am currently working on an app that receives the BOOT_COMPLETED action using a Broadcast Receiver. The receiver is statically registered in the AndroidManifest.xml.
It works on the next boot after installation for android 2.2 but not 3.1. With 3.1 I have to start the app once before the broadcast receiver gets the BOOT_COMPLETED action when booting.
I suspect that something changed in 3.1 that is causing my receiver to be inactive until the app is started once.
Has anyone ever seen this before or know how to stop this behavior? Any Help would be greatly appreciated. Thanks, Tom.
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.receiver"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="TestReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
TestReceiver.java:
package com.test.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class TestReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("TestReceiver", "onReceive() was called");
}
}
MainActivity.java:
package com.test.receiver;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}