Following code used:
public class ForceUpdateAsync extends AsyncTask<String, String,
JSONObject> {
VersionListener mWsCallerVersionListener;
private String latestVersion;
private String currentVersion;
private Context context;
public ForceUpdateAsync(String currentVersion, Context context, VersionListener callback) {
this.currentVersion = currentVersion;
this.context = context;
mWsCallerVersionListener = callback;
}
@Override
protected JSONObject doInBackground(String... params) {
try {
latestVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=" +
context.getPackageName() + "&hl=en")
.timeout(30000)
.userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
.referrer("http://www.google.com")
.get()
.select("div.hAyfc:nth-child(4) > span:nth-child(2) > div:nth-child(1) > span:nth-child(1)")
.first()
.ownText();
Log.e("latestversion", "---" + latestVersion);
} catch (Exception e) {
e.printStackTrace();
mWsCallerVersionListener.onGetResponse(false);
}
return new JSONObject();
}
@Override
protected void onPostExecute(JSONObject jsonObject) {
if (latestVersion != null) {
if (Float.parseFloat(currentVersion)<Float.parseFloat(latestVersion)) {
mWsCallerVersionListener.onGetResponse(true);
} else {
mWsCallerVersionListener.onGetResponse(false);
}
} else {
mWsCallerVersionListener.onGetResponse(false);
}
super.onPostExecute(jsonObject);
}
}
Getting following exception:
Attempt to invoke virtual method 'java.lang.String org.jsoup.nodes.Element.ownText()' on a null object reference
my assumption is that issue occurred due to updated html of play store. how I can get latest version of Play-store build?