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

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

问题描述

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

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 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天全站免登陆