由于更新的Play商店设计,无法获得最新版本的Play Store Build
使用以下代码:
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);
}
}
以下例外:
尝试调用虚拟方法'java.lang.string org.jsoup.nodes.element.owntext()'null对象参考
我的假设是由于更新的play商店HTML而出现的问题。我如何获得最新版本的Play-tore Build?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论