我是Android编程世界的新手。 我试图使用https://developers.google.com/+/mobile/android/samples/quickstart-android处的文档创建G +登录。 (我用android工作室做过)
我已成功登录并注销我的Moto-G(Android版本5.0.2)。但是,我无法对三星Galaxy Trend(Android版本4.1.2)做同样的事情。我在这里遇到的错误是:“ Google Play服务不可用。此应用程序将关闭。”
除了文档中提到的内容之外,我没有做任何其他事情。 有人可以指导我这里出了什么问题吗?
谢谢!
答案 0 :(得分:0)
当我的android没有在这里更新时发生这种情况是检查的代码,我在2年前使用过
**
* Verify that Google Play services is available before making a request.
*
* @return true if Google Play services is available, otherwise false
*/
private boolean servicesConnected() {
// Check that Google Play services is available
int resultCode =
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());
// If Google Play services is available
if (ConnectionResult.SUCCESS == resultCode) {
// In debug mode, log the status
//Log.d(LocationUtils.APPTAG, getString(R.string.play_services_available));
// Continue
return true;
// Google Play services was not available for some reason
} else {
// Display an error dialog
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, getActivity(), 0);
if (dialog != null) {
ErrorDialogFragment errorFragment = new ErrorDialogFragment();
errorFragment.setDialog(dialog);
errorFragment.show(getFragmentManager(), "Baja Wanted");
}
return false;
}
}
/**
* Show a dialog returned by Google Play services for the
* connection error code
*
* @param errorCode An error code returned from onConnectionFailed
*/
private void showErrorDialog(int errorCode) {
// Get the error dialog from Google Play services
Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(
errorCode,
getActivity(),
CONNECTION_FAILURE_RESOLUTION_REQUEST);
// If Google Play services can provide an error dialog
if (errorDialog != null) {
// Create a new DialogFragment in which to show the error dialog
ErrorDialogFragment errorFragment = new ErrorDialogFragment();
// Set the dialog in the DialogFragment
errorFragment.setDialog(errorDialog);
// Show the error dialog in the DialogFragment
errorFragment.show(getFragmentManager(), "Baja Wanted");
}
}
}
/**
* Define a DialogFragment to display the error dialog generated in
* showErrorDialog.
*/
public static class ErrorDialogFragment extends DialogFragment {
// Global field to contain the error dialog
private Dialog mDialog;
/**
* Default constructor. Sets the dialog field to null
*/
public ErrorDialogFragment() {
super();
mDialog = null;
}
/**
* Set the dialog to display
*
* @param dialog An error dialog
*/
public void setDialog(Dialog dialog) {
mDialog = dialog;
}
/*
* This method must return a Dialog to the DialogFragment.
*/
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return mDialog;
}
}
}
Google Play服务工具
https://developers.google.com/android/reference/com/google/android/gms/common/GooglePlayServicesUtil