还有就是可以实施获取当前Play商店版本一招。
public void getUpdate() {
final String appPackageName = getPackageName();
Document doc = null;
try {
doc = Jsoup.connect("https://play.google.com/store/apps/details?id=" + appPackageName).get();
} catch (IOException e) {
e.printStackTrace();
}
// Document doc = Jsoup.parse(resString);
if(doc!=null) {
Element meta = doc.select("div[itemprop=softwareVersion]").first();
String content = meta.ownText();
System.out.println(content);
Double playStoreVersion = Double.valueOf(content);
Double currentVersion = getVersionName();
if (playStoreVersion > currentVersion) {
try {
new AlertDialog.Builder(SplashScreen.this)
.setTitle("Alert")
.setMessage("Update Is Available.Do You Want To Update?")
.setIcon(R.mipmap.ic_launcher)
.setCancelable(false)
.setPositiveButton("Update",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
try {
startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)), UPDATE_FROM_PLAY_STORE_REQUEST);
} catch (Exception e) {
try {
startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)), UPDATE_FROM_PLAY_STORE_REQUEST);
} catch (Exception e1) {
}
}
dialog.dismiss();
}
}).setNegativeButton("Not yet", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
Handler();
}
}).show();
//startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
try {
startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)), UPDATE_FROM_PLAY_STORE_REQUEST);
} catch (Exception e) {
}
}
} else {
Handler();
}
}else {
Handler();
}
}
获取我们自己的应用程序的版本。
public Double getVersionName() {
Double VersionName = 0.0;
try {
String vName = SplashScreen.this.getPackageManager().getPackageInfo(SplashScreen.this.getPackageName(), 0).versionName;
VersionName = Double.valueOf(vName);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return VersionName;
}
检查[this](https://github.com/rampo/UpdateChecker)是否仍然有效。如果是这样,那么你不需要进行任何API调用。 –
@IceMAN:看起来不错。但我仍然更喜欢更轻量级的东西。这就是为什么我想知道,如果我可以对Playstore进行API调用并自己获取这些数据。 – Rohitesh
@IceMAN:所以,我查看了代码,他们也在Playstore上为应用程序抓取网页。这是我最初的想法,但据我看,它不是一个非常优雅的解决方案。所以,想知道是否有API。 – Rohitesh