强制用户拥有最新的Andr​​oid的应用程序版本 [英] Force users to have latest android app version

查看:193
本文介绍了强制用户拥有最新的Andr​​oid的应用程序版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能检查的Andr​​oid应用程序启动时,用户是否有它的最新版本,并强迫他更新,如果他有没有?或者至少checkt是否有新版本,并告诉他,该应用程序将只重新工作时,他下载并安装该更新?

背景是,我有一个应用程序需要与服务器进行通信。当我改变的东西在服务器和客户端之间的接口我想,以确保客户端具有最新的版本。

有没有原生的方式做到这一点?还是我必须要检查这个我自己?

如果你有一个MySQL数据库是这只访问?是有可能做到这一点只用纯文本在网页上,并把它与当前的应用程序版本检查?

解决方案
  

是有可能只做到这一点   网页上的纯文本,并将它   检查与当前应用程序的版本?

这就是我会做:

检查服务器上的最新版本,在文本文件中:

  HttpClient的客户端=新DefaultHttpClient();
HTTPGET请求=新HTTPGET(URL);
HTT presponse响应= client.execute(要求);

字符串latestVersion =;
。InputStream的时间= response.getEntity()的getContent();
的BufferedReader读卡器=新的BufferedReader(新的InputStreamReader(在));
StringBuilder的海峡=新的StringBuilder();
串线= NULL;
而((行= reader.readLine())!= NULL)
{
    str.append(线);
}
附寄();
latestVersion = str.toString();
 

然后把它比作安装的版本:

 私人字符串getSoftwareVersion(){
    尝试 {
            PackageInfo packageInfo = getPackageManager()getPackageInfo(getPackageName(),0)。
            返回packageInfo.versionName; //编辑:版本code会更好
    }赶上(PackageManager.NameNotFoundException E){
            Log.e(TAG,包找不到名称,E);
    };
 }
 

Is it possible to check on startup of an Android app whether the user has the latest version of it and force him to update if he has not? Or at least checkt whether there is a new version and tell him, that the app only will work again when he downloads and installs the update?

Background is that I have an app that needs to communicate with a server. When I change something in the interface between server and client I want to assure that the client has the latest version.

Is there any native way to do this? Or do I have to check this on my own?

Is this only accessible if you have a mysql database? is it possible to do this with just plain text on a webpage and have it checked with the current app version?

解决方案

is it possible to do this with just plain text on a webpage and have it checked with the current app version?

That's what I would do:

Checking latest version on your server, in a text file:

HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);

String latestVersion = "";
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null)
{
    str.append(line);
}
in.close();
latestVersion = str.toString();

and then compare it to the installed version:

private String getSoftwareVersion() {
    try {
            PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
            return packageInfo.versionName;//EDIT: versionCode would be better
    } catch (PackageManager.NameNotFoundException e) {
            Log.e(TAG, "Package name not found", e);
    };
 }

这篇关于强制用户拥有最新的Andr​​oid的应用程序版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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