我试图在我的android项目中使用Google。当我调用以下函数时
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服务正在工作“,但在那之后,它就会退出if并返回false。
Google服务已正确安装在我的SDK中。
发布于 2018-10-09 20:02:04
尝试这个以获得布尔值并打印
public static boolean checkPlayServices(Activity activity) {
final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(activity);
if (resultCode != ConnectionResult.SUCCESS) {
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(activity, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
.show();
Log.d(TAG, "This device have google play services");
} else {
Log.d(TAG, "This device does not have google play services");
}
return false;
}
return true;
}现在打印checkPlayServices(活动)
https://stackoverflow.com/questions/52728218
复制相似问题