【问题标题】:How can I force the device user to use a specific version of HMS core that inline with some HMS services?如何强制设备用户使用与某些 HMS 服务内联的特定版本的 HMS 核心?
【发布时间】:2021-03-03 01:10:54
【问题描述】:

我的一些应用程序功能需要特定版本的 HMS 核心才能使用,因此该功能可以毫无问题地运行,我试图找到一种方法来强制设备用户将 HMS 核心更新到最新版本,以使确保应用程序不会崩溃,但我找不到任何方法,所以请帮助我。

【问题讨论】:

    标签: huawei-mobile-services


    【解决方案1】:

    没有提供这样的接口。如果当前的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下载页面。

    【讨论】:

      猜你喜欢
      • 2021-12-14
      • 2021-08-07
      • 2021-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-05
      • 2023-03-03
      相关资源
      最近更新 更多