Roh*_*esh 6 android google-play google-play-services
问题:
我想从 Google Playstore 获取生产中应用的最新版本。如果最新版本的某些更改需要它,我想添加强制升级的功能。
我有什么:
我目前正在我的服务器上更新应用程序的最新版本,并强制应用程序请求它并根据它检查版本。这有效。但是我不想每次发布新版本时都更新我的服务器。我希望该应用程序能够从 Google Playstore 获取相同的信息。
我需要什么:
我可以在客户端(在应用程序上)处理逻辑。我所需要的只是对 Playstore 的 API 调用,以获取我自己的应用程序的最新生产版本。如果有人可以在这方面帮助我提供一些指导,那将非常有帮助。
干杯,
罗希特什
小智 1
您可以实施一个技巧来获取当前的 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();
}
}
Run Code Online (Sandbox Code Playgroud)
获取我们自己的应用程序的版本。
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;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3021 次 |
最近记录: |