Android/Google 播放 - 应用可以更新吗 运行
Android/Google Play - Can an App Update While it Is Running
我正在构建一个旨在持续 运行 的应用程序。此外,用户在使用时会被锁定在应用程序中(通过固定功能)。当该应用有一段时间未检测到用户交互时,它会自行取消固定,调用 Android 梦想服务,并显示各种屏幕保护程序。当用户点击设备时,它 'wakes up'、转到主屏幕并重新定位自己。
我需要我的应用自动更新。但是,考虑到当时的情况,我很难做到。它似乎根本没有更新,或者根据我的一位同事的说法,更新但关闭了应用程序。
有没有办法让应用程序在 运行 期间检测、下载和安装更新,然后在必要时自行重新启动?最好的方法是什么?
非常感谢。
Is there a way for the app to detect, download, and install an update while running
这由 google Play 商店为您处理。一个应用在升级到新版本时被杀死,所以新版本安装顺利并且数据没有损坏。
if necessary, relaunch itself?
如果您想在升级后保留 运行(或者更确切地说,重新启动应用程序),是的,您必须做一些额外的事情。
我使用的一种方式是这样的:
放入清单:
<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
.
我正在构建一个旨在持续 运行 的应用程序。此外,用户在使用时会被锁定在应用程序中(通过固定功能)。当该应用有一段时间未检测到用户交互时,它会自行取消固定,调用 Android 梦想服务,并显示各种屏幕保护程序。当用户点击设备时,它 'wakes up'、转到主屏幕并重新定位自己。
我需要我的应用自动更新。但是,考虑到当时的情况,我很难做到。它似乎根本没有更新,或者根据我的一位同事的说法,更新但关闭了应用程序。
有没有办法让应用程序在 运行 期间检测、下载和安装更新,然后在必要时自行重新启动?最好的方法是什么?
非常感谢。
Is there a way for the app to detect, download, and install an update while running
这由 google Play 商店为您处理。一个应用在升级到新版本时被杀死,所以新版本安装顺利并且数据没有损坏。
if necessary, relaunch itself?
如果您想在升级后保留 运行(或者更确切地说,重新启动应用程序),是的,您必须做一些额外的事情。
我使用的一种方式是这样的:
放入清单:
<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
.