根據您將如何經常做的更新,你可以簡單地在您的服務器上的網頁,讓您的可用最新版本,如果它不符合目前的一個,提示用戶意圖在您的應用中打開Play商店。
基本上,ask the server最新的版本是什麼(你需要在一個try/catch來包裝它並添加網絡許可清單):
URL url = new URL("mysite.com/thefile.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline character(s)
}
in.close();
來自服務器的響應可能會是像{"latestVersion": "1.004"}
,你可以查看當前安裝的版本:
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
version = pInfo.versionName;
比較他們,並提示一個對話框或任何用戶,然後推出Play商店中,通過使用代碼中發現here:
final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
}
爲了澄清,你會在你的服務器手動更新版本,這樣可能會或可能不會是你根據你的更新的頻率,以及如何往往你忘事的一個選項:P
你能告訴我如何從服務器得到你所說的回覆嗎?我正在做的所有其他部分,但我沒有取得迴應。 – Sree
完成,祝你好運 –
我很抱歉問,我可以知道谷歌Play商店裏這個'thefile.txt'是什麼嗎? – Sree