2014-05-21 66 views
0

我試圖在我的應用程序內顯示更新提醒,如果我已在我的google play app中更新,請參閱this作爲參考,我已設法從Play商店獲得響應。但從Play商店看來更新的反應就像這樣。應用程序更新來自Google play的應用程序內部提醒

We're sorry, the requested URL was not found on this server

我的問題是我怎麼知道我的應用程序裏面,如果有可用更新的谷歌玩店?

和谷歌播放不支持apk中的私人更新鏈接,所以有沒有其他的方式來獲取應用程序內的更新從playstore。 在此先感謝。

回答

1

根據您將如何經常做的更新,你可以簡單地在您的服務器上的網頁,讓您的可用最新版本,如果它不符合目前的一個,提示用戶意圖在您的應用中打開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

+0

你能告訴我如何從服務器得到你所說的回覆嗎?我正在做的所有其他部分,但我沒有取得迴應。 – Sree

+0

完成,祝你好運 –

+0

我很抱歉問,我可以知道谷歌Play商店裏這個'thefile.txt'是什麼嗎? – Sree

相關問題