Here is the manifest entry for one of my receivers that is working:
<receiver
android:enabled="true"
android:name=".receivers.StartupReceiver"
android:label="@string/app_notify_boot_label"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Also, I wouldn't hardcode the BootCompleted string like you are currently
doing in your receiver... If you really want to check the action like that
I would use this:
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)
If the Android devs decide to change the underlying string in a future SDK
release you will be SOL. But by checking against this public variable in
Intent you will always be safe.
On Mon, Feb 28, 2011 at 9:08 AM, Kui Zou <[email protected]> wrote:
> Hi,
>
> I have defined a BroadcastReceiver* -- *StartupIntentReceiver, as
> follows:
>
> *public class StartupIntentReceiver extends BroadcastReceiver {*
> * private static final String ACTION =
> "android.intent.action.BOOT_COMPLETED";*
> *
> *
> * @Override*
> * public void onReceive(Context context, Intent intent) {*
> * if (intent.getAction().equals(ACTION)) {*
> * Intent service = new Intent(context, MyService.class);*
> * context.startService(service);*
> * } *
> * }*
> *}*
>
> I also added the receiver and required permission to AndroidManifest.xml:
> * <receiver android:name="com.test.StartupIntentReceiver">*
> * <intent-filter>*
> * <action
> android:name="android.intent.action.BOOT_COMPLETED"></action>*
> * </intent-filter>*
> * </receiver>*
> *<uses-permission
> android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
> *
> *
> *
> But it seems that the defined Service (MyService) does not run when the
> system boot up. Any ideas on how to make Service auto-start when system boot
> up?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en