我如何使我过时的应用程序版本显示更新可用的对话框? [英] How can i make my outdated app version show a dialog that an update is available?

查看:163
本文介绍了我如何使我过时的应用程序版本显示更新可用的对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚是Android编程的新手,所以让我说一个版本1.0的应用程序,然后我发布了同一个应用程序的另一个版本,让我们说1.1版本。我应该在我的应用程序中添加什么代码来检查更新并强制过时的应用程序版本退出时,用户不更新它,并将用户重定向到下载链接,如果他/她想要更新我的应用程序?谢谢

I am just new to android programming, so let's say i have an app of version 1.0 .. then i released another version for the same app, let's say version 1.1 .. what code should i add in my app to check for updates and forces the outdated app versions to exit when a user does not update it and redirects the user to the download link if he/she wants to update my app ?. thanks

简而言之,过时的应用程序无法使用,因为将出现一个警告对话框,告知用户他必须将我的应用程序更新为可用的较新版本。

in short, the outdated apps cannot be used because an alert dialog will appear that tells the user he must update my app to a newer version available

PS,我的应用程序不在Play商店..因为我是一个新的Android程序员,我没有25 $

PS, my app is not in the Play Store yet .. as i am a new android programmer and i have no 25$

推荐答案

您可以在第一个版本上构建警报对话框,当您将新版本上传到Google Play时,您可以使用gcm通知您的应用程序。并要求它显示alertDialog。

you can build the alert dialog on the first version, when you upload new version to google play you can notify your app with gcm. and ask it to show the alertDialog.

1.在sharedPref中添加appVersion变量。

1.save appVersion variable in sharedPref.

2.在你的应用程序启动:

2.in your application startup :

if(appVersion !=  getAppVersion(context))
{
   showAlertDialog()
}


private static int getAppVersion(Context context) {
    try {
        PackageInfo packageInfo = context.getPackageManager()
                .getPackageInfo(context.getPackageName(), 0);
        return packageInfo.versionCode;
    } catch (NameNotFoundException e) {
        // should never happen
        throw new RuntimeException("Could not get package name: " + e);
    }
}

3.当您有新的更新时,发送新版本号( gcm ),并修改您的sharedPref。

3.when you have a new update,send the new version number (by gcm) and edit your sharedPref.

这篇关于我如何使我过时的应用程序版本显示更新可用的对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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