問題描述
在 Google Play 上查詢應用程序當前版本的更快方法? (Faster Way to Query Application's Current Version on Google Play?)
I would like to be able to compare, on application start, the running version against the same application's version currently on Google Play.
I found a nice way to this, described here:
public String getLatestVersionNumber() {
String versionNumber = "0.0.0";
try {
Document doc = Jsoup.connect("http://www.appbrain.com/app/wallpaper-switch/com.mlevit.wallpaperswitch").get();
Elements changeLog = doc.select("div.clDesc");
for (Element div : changeLog) {
String divText = div.text();
if (divText.contains("Version")) {
return divText.split(" ")[1];
}
}
}
catch (IOException e) {
e.printStackTrace();
}
return versionNumber;
}
But it's way too slow and significantly hampers user experience on application start.
Is there a faster way to query application's current version on Google Play?
Perhaps some hidden LVL or in-app billing API?
參考解法
方法 1:
Are you sure there isn't any API that provides the Google Play version much faster?
Well, by definition, network access is slow. Even if Google Play had a documented, supported, and licensed API (they don't as of the time of this writing), it would only be incrementally faster than what you are doing.
Can you post your suggestion on how to do that via AsyncTask?
Step #1: Create a file.
Step #2: In that file, type in your version number, optionally along with other data (e.g., description of update) in some format (e.g., JSON).
Step #3: Upload that file to some well-known stable URL.
Step #4: Create an AsyncTask
, putting the HTTP request for your file in doInBackground()
of an AsyncTask
, with updating your UI (preferably via something non-modal) in the onPostExecute()
of that same AsyncTask
.
Here is a sample project demonstrating an AsyncTask
that performs an HTTP operation (pulling a weather forecast from the US National Weather Service) and parsing the result, updating the UI (populating a WebView
) when done.
(by Bill The Ape、CommonsWare)