安装我的应用程序时的 android 意图

发布于 2024-12-21 15:12:01 字数 521 浏览 0 评论 0原文

安装应用程序时我需要执行操作。我已经考虑过使用

Intent.PACKAGE_ADDED

,但我没有收到正在安装的应用程序中的意图。我想在第一次安装我的应用程序时运行代码。

该用例是注册在线服务。我可以列出 BOOT_COMPLETED,如果应用程序已安装,这很好,但我需要在用户首次安装应用程序时处理这种情况。

这篇文章, 您可以运行当您的应用程序安装在 Android 上时的意图或脚本?

建议监听 TIMER_TICK 并在第一次广播时执行注册并设置一个标志,以便不在下一个 TIMER_TICK 时执行它。这似乎有问题,因为无论您是否在接收器中执行某些操作,您仍然每分钟都会启动接收器并在此过程中耗尽电池。

有更好的解决方案吗?

i need to perform an action when my application is installed. i've looked into using

Intent.PACKAGE_ADDED

but i don't receive the intent in the app that's being installed. i want to run code when my app is installed for the first time.

the use case is registering with an online service. i can listed for BOOT_COMPLETED which is fine if the app is already installed, but i need to handle the case when the user first installs the app.

this post,
Can you run an intent or script when your app gets installed on Android?

suggests listening to TIMER_TICK and on the first broadcast, perform the registration and set a flag so as not to perform it upon the next TIMER_TICK. this seems problematic because whether you do something or not in the receiver, you are still starting your receiver every single minute and using up battery in the process.

is there a better solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

计㈡愣 2024-12-28 15:12:01

没有可以捕捉到的可靠事件。即使是 TIMER_TICK 也只能在 Android 3.1 以下运行。从 3.1 开始。从那时起,您将无法接收系统广播,直到您的应用程序处于活动状态(这意味着用户必须至少手动启动一次)。

启动对停止的应用程序的控制

从Android 3.1开始,系统的包管理器会跟踪
处于停止状态的应用程序并提供了一种方法
控制它们从后台进程和其他进程的启动
应用程序。

[...]

请注意,系统添加了 FLAG_EXCLUDE_STOPPED_PACKAGES致所有人
广播意图。
这样做是为了防止来自后台的广播
无意或不必要地启动组件的服务
停止的应用程序。
[..]

应用程序首次安装时处于停止状态,但
尚未启动
以及当它们被用户手动停止时
(在管理应用程序中)。

来自 3.1。发行说明

我建议在用户第一次启动您的应用程序时进行初始工作。

There is no reliable event that you can catch. Even TIMER_TICK will only work below Android 3.1. From 3.1. onwards you can't receive system broadcasts until your app is in active state (which means the user has to launch it at least once manually).

Launch controls on stopped applications

Starting from Android 3.1, the system's package manager keeps track of
applications that are in a stopped state and provides a means of
controlling their launch from background processes and other
applications.

[...]

Note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGES to all
broadcast intents.
It does this to prevent broadcasts from background
services from inadvertently or unnecessarily launching components of
stoppped applications.
[..]

Applications are in a stopped state when they are first installed but
are not yet launched
and when they are manually stopped by the user
(in Manage Applications).

from the 3.1. release notes

I recommend to do your intitial work when the user starts your app for the first time.

吝吻 2024-12-28 15:12:01

如果您愿意假设已安装 Google Android Market 应用程序,则可以使用 INSTALL_REFERRER。有关详细信息,请参阅从 Android Market 安装应用后获取引荐来源网址

If you're willing to assume that the Google Android Market app is installed, you could use INSTALL_REFERRER. See Get referrer after installing app from Android Market for more info.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文