已安装我的应用程序时,Android的意图我的、意图、应用程序、Android

2023-09-06 04:42:14 作者:simple

我需要的是我的安装​​应用程序时要执行的操作。我已经研究过使用

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

Intent.PACKAGE_ADDED

但我不接收正在被安装的应用程序的意图。我希望在我的应用程序被安装在第一次运行code。

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.

用例正在注册与在线服务。我可以列出BOOT_COMPLETED如果已安装的应用程序,这是很好的,但我需要处理的情况下,当用户第一次安装的应用程序。

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.

这个帖子, Can您运行的意图或脚本时,您的应用程序被安装在Android?

提示收听TIMER_TICK和关于在第一广播,执行注册,并设置一个标志以便不基于下一TIMER_TICK执行它。这似乎是有问题的,因为不管你做某件事,或者不接收,你还在启动接收机的每一分钟,并使用了电池的过程中。

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?

推荐答案

有可能让你没有可靠的事件。即使 TIMER_TICK 将只以下的Andr​​oid 3.1。 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).

上停止应用程序启动控制

从安卓3.1开始,系统的软件包管理器会跟踪   是处于停止状态,并提供一种手段应用   控制自己的发布仪式,由后台进程等   应用程序。

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.

[...]

需要注意的是该系统增加了 FLAG_EXCLUDE_STOPPED_PACKAGES 所有   广播意图。它这样做是从后台prevent广播   从无意或不必要的启动组件服务   stoppped应用程序。   [..]

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).

从href="http://developer.android.com/sdk/android-3.1.html" rel="nofollow"> 3.1