Place API Error: Unhandled exceptions

Place API Error: Unhandled exceptions

PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
startActivityForResult(builder.build(MainActivity.this), PLACE_PICKER_REQUEST);

我正在使用此源代码,但在 builder.build(MainActivity.this) 处出现如下错误:

Unhandled exceptions: com.google.android.gms.common.GooglePlayServicesRepairableException, com.google.android.gms.common.GooglePlayServicesNotAvailableException

我检查了它的功能 API(compile 'com.google.android.gms:play-services-places:11.4.2'bulid.gradle 上)。我该如何解决?

只需 enable/update/upgrade google 在您的 phone 上播放服务。

official documentation 中所写,生产阶段的最佳解决方案是:

GooglePlayServicesRepairableExceptions are special instances of UserRecoverableExceptions which are thrown when Google Play Services is not installed, up-to-date, or enabled. In these cases, client code can use getConnectionStatusCode() in conjunction with getErrorDialog(android.app.Activity, int, int) to provide users with a localized Dialog that will allow users to install, update, or otherwise enable Google Play services.

发生这种情况是因为您的播放服务不是最新的... 下面的代码将向用户显示一个对话框,用于更新 Play 服务

 Int status;
 @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        if (status != ConnectionResult.SUCCESS) {
            if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
                GooglePlayServicesUtil.getErrorDialog(status, this,
                        100).show();
            } 
        }
}