【发布时间】:2021-03-03 01:10:54
【问题描述】:
我的一些应用程序功能需要特定版本的 HMS 核心才能使用,因此该功能可以毫无问题地运行,我试图找到一种方法来强制设备用户将 HMS 核心更新到最新版本,以使确保应用程序不会崩溃,但我找不到任何方法,所以请帮助我。
【问题讨论】:
我的一些应用程序功能需要特定版本的 HMS 核心才能使用,因此该功能可以毫无问题地运行,我试图找到一种方法来强制设备用户将 HMS 核心更新到最新版本,以使确保应用程序不会崩溃,但我找不到任何方法,所以请帮助我。
【问题讨论】:
没有提供这样的接口。如果当前的HMS Core不满足要求,HMS会自动引导用户升级HMS Core。
我之前尝试过为这个senarior写代码,你也可以试试下面的代码:
public void checkUpdate(Context context) {
int requiredVersion = 50005300;
Log.d("mymsg", "" +
HMSPackageManager.getInstance(context).getHmsVersionCode());
Log.d("mymsg", "" +
HMSPackageManager.getInstance(context).hmsVerHigherThan(requiredVersion));
if (HMSPackageManager.getInstance(context).hmsVerHigherThan(requiredVersion))
{ initDialog(MainActivity.this); } }
private void initDialog(Activity activity) {
new AlertDialog.Builder(activity)
.setMessage("Please update HMS Core")
.setCancelable(false)
.setPositiveButton("OK", (dialog, which) -> {
intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("appmarket://details?
id="+HMSPackageManager.getInstance(activity).getHMSPackageName()));
activity.startActivity(intent);
})
.create()
.show();
}
此代码检查当前 HMS Core 版本是否早于所需版本。如果低于要求的版本,则显示AppGallery Hms Core下载页面。
【讨论】: