安装我的应用程序时的 android 意图
安装应用程序时我需要执行操作。我已经考虑过使用
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有可以捕捉到的可靠事件。即使是
TIMER_TICK
也只能在 Android 3.1 以下运行。从 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).from the 3.1. release notes
I recommend to do your intitial work when the user starts your app for the first time.
如果您愿意假设已安装 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.