如何要求更新播放服务并添加 "This app won't run unless you update Google Play services"

How to require updated play services and add "This app won't run unless you update Google Play services"

我创建了一个使用最新播放服务 (7.8) 的应用程序。此应用程序使用新条形码 reader,它对应用程序的功能至关重要。当我在寻找这个问题的答案时,我发现在使用地图 API 时,应用程序会强制用户更新播放服务。现在我无法做到这一点。

我使用 genymotion 作为我的模拟器并安装了过时版本的播放服务。它可以很好地运行应用程序,但条码扫描器不是 运行。日志还说:

Didn't find class "com.google.android.gms.vision.client.DynamiteNativeBarcodeDetectorCreator" 

我已经在 AndroidManifest 的应用程序标签中添加了这个:

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

当您打开应用程序时,环聊和其他 google 应用程序也有这样的阻止,强制用户在使用该应用程序之前先安装更新的播放服务。

抱歉我的英语不好。感谢您的帮助!

可能是我搜索的不够仔细。里面有个说明 android developer guide's site

我只在 activity 的 onResume() 方法中添加了这段代码:

Dialog errorDialog = GoogleApiAvailability.getInstance().getErrorDialog(this,
            GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(getApplicationContext()),
                    REQUEST_CODE_RECOVER_PLAY_SERVICES);
    if (errorDialog != null)
        errorDialog.show();