安装完成后自动启动的Andr​​oid应用自动启动、安装完成后、oid、Andr

2023-09-05 06:37:46 作者:少年多梦,不多心

我知道如何引导与 BOOT_COMPLETED 意图动作后自动启动,但我没有找到如何自动启动已经安装在设备上刚结束的应用程序。

I know how to autostart after boot with the BOOT_COMPLETED intent action, but I didn't find how to autostart an application just after it has been installed on the device.

有关我的应用程序,我想设置一个报警安装后,我看着的 PACKAGE_ADDED 原意行动,但它说,新安装包不会收到该广播。

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.

任何意见?

在此先感谢

推荐答案

正如你提到的,有没有办法接受自己的 PACKAGE_ADDED 事件;你只需要在每次启动应用程序时检查一个标志。

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.

例如:

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();
}

您可以在应用程序把这个类,或在你的发射器的的onCreate 方法。

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