开发者

Autostart Android application after installation complete

I know how to autostart after boot with the BOOT_COMPLETED intent action, but I didn't find how to autostart an applic开发者_如何学Cation just after it has been installed on the device.

For my application I would like to set an alarm after the install, I looked at the PACKAGE_ADDED intent action but it says that the newly installed package does not receive this broadcast.

Any advice ?

Thanks in advance


As you mention, there's no way of receiving your own PACKAGE_ADDED event; you just have to check for a flag each time you start your application.

For example:

SharedPreferences prefs = getPreferences(MODE_PRIVATE);
if (!prefs.contains(KEY_FIRST_RUN)) {
    /* do some one-off stuff here */
    prefs.edit().putBoolean(KEY_FIRST_RUN, false).commit();
}

You could put this in your Application class, or in your launcher's onCreate method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜