【发布时间】:2018-10-09 19:39:52
【问题描述】:
我正在尝试在我的 android 项目中使用 Google Maps API。 当我调用以下函数时
public boolean checkGoogleServices(){
Log.d(TAG, "isServicesOk: checking google services version");
int available = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(Home.this);
if (available == ConnectionResult.SUCCESS){
Log.d(TAG, "isServicesOk: Google Play Services is working");
Toast.makeText(this, "OK", Toast.LENGTH_LONG).show();
return true;
}
else if(GoogleApiAvailability.getInstance().isUserResolvableError(available)){
Log.d(TAG, "isServicesOk: an error occured but we can fix it");
Dialog dialog = GoogleApiAvailability.getInstance().getErrorDialog(Home.this, available, ERROR_DIALOG_REQUEST);
dialog.show();
}else{
Toast.makeText(this, "You can't make maps request", Toast.LENGTH_LONG).show();
}
return false;
}
if (available == ConnectionResult.SUCCESS)的结果是true,实际上程序在控制台上写了日志“google play services is working”,但之后它就退出了if并返回false。
Google Play 服务已正确安装在我的 SDK 中。
【问题讨论】:
-
它返回
false,因为你已经写了return false,而且你永远不会返回任何其他东西。