Android/Google Play-应用程序运行时是否可以更新 [英] Android/Google Play - Can an App Update While it Is Running

查看:249
本文介绍了Android/Google Play-应用程序运行时是否可以更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个旨在连续运行的应用程序.此外,在使用应用程序时,用户被锁定在应用程序中(通过固定功能).当该应用一段时间未检测到用户交互时,它会自行取消固定,调用Android dream服务,并显示各种屏幕保护程序.当用户点击设备时,它会醒来",进入主屏幕,然后重新定位.

I am building an app that is designed to run continuously. Furthermore, the user is locked into the app (via the pinning feature) when it is being used. When the app has not detected user interaction for a while, it unpins itself, calls the Android dream service, and displays a screensaver of sorts. When the user taps the device, it 'wakes up', goes to the main screen, and repins itself.

我需要我的应用程序才能自动更新.但是,考虑到这种情况,我很难做到这一点.它似乎根本没有更新,或者根据我的一位同事的说法,已更新但关闭了该应用程序.

I need my app to auto-update. However, given the circumstances, I have had difficulty in doing so. It simply does not seem to update, or according to one of my colleagues, updated but closed the app.

应用程序是否可以在运行时检测,下载和安装更新,然后在必要时重新启动自身?最好的方法是什么?

Is there a way for the app to detect, download, and install an update while running, and then, if necessary, relaunch itself? What would be the best approach?

非常感谢.

推荐答案

应用程序是否可以在运行时检测,下载和安装更新

Is there a way for the app to detect, download, and install an update while running

这是由Google Play商店为您处理的.将要升级到新版本的应用程序将被杀死,因此新版本的安装很流畅,并且数据没有损坏.

This is handled for you by google play store. An app is killed when it is going to be upgraded to a new version so the installation of the new version is smooth and data is not corrupted.

是否有必要重新启动?

if necessary, relaunch itself?

如果要在升级后继续运行(或者重新启动应用程序),是的,您还必须做一些其他事情.

If you want to keep running (or rather, restart the app) after an upgrade, yes you have to do some additional stuff.

我使用的一种方法是:
放入清单:

A way that I use is this:
Put in manifest:

<receiver android:name=".receivers.AppUpgraded">
    <intent-filter>
        <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
    </intent-filter>
</receiver>


public class AppUpgraded extends BroadcastReceiver {

    @Override
    public void onReceive(final Context context, Intent intent) {
        // your app was just upgraded, restart stuff etc.
    }
}

请注意,还有一个action.PACKAGE_REPLACED会为任何已升级的应用程序触发.您可能只对自己的应用程序升级感兴趣,因此请使用action.MY_PACKAGE_REPLACED.

Note there is also a action.PACKAGE_REPLACED which will trigger for ANY app that is upgraded. You're likely only interested in the upgrade of your own app, so use action.MY_PACKAGE_REPLACED.

这篇关于Android/Google Play-应用程序运行时是否可以更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆