错误 Google 登录于 Android
Error Google Login on Android
我的应用说:
Google play services is not available. this application will close
我使用的代码是https://github.com/googleplus/gplus-quickstart-android
有什么建议吗?
不清楚您是否在检查设备上是否安装了 GooglePlayServices。我没有在您链接的代码中看到检查。
This webpage describes how to verify that GooglePlayServices is installed on a device and how to handle failures. The information is not completely current, but still provides a good outline of the processing. The GooglePlayServicesUtil class 提供检查是否安装了 PlayServices 的方法,如果缺少,则显示一个对话框以允许用户安装它。
部分代码来自网页:
private boolean checkPlayServices() {
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (status != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
showErrorDialog(status);
} else {
Toast.makeText(this, "This device is not supported.",
Toast.LENGTH_LONG).show();
finish();
}
return false;
}
return true;
}
private int REQUEST_CODE = 1234;
private void showErrorDialog(int code) {
GooglePlayServicesUtil.getErrorDialog(code, this, REQUEST_CODE).show();
}
我在这里玩一些代码给你建议:
strings.xml:
<string name="lbl_play_service">This application needs Google Play Service, you must install it first.</string>
<string name="play_service_url">market://details?id=com.google.android.gms</string>
<string name="play_service_web">https://play.google.com/store/apps/details?id=com.google.android.gms</string>
Some javas:
@Override
protected void onResume() {
super.onResume();
checkPlayService();
}
/**
* To confirm whether the validation of the Play-service of Google Inc.
*/
private void checkPlayService() {
final int isFound = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (isFound == ConnectionResult.SUCCESS) {
//Device has updated version of play-service.
} else {
//You need to store to update play-service.
new Builder(this).setTitle(R.string.application_name).setMessage(R.string.lbl_play_service).setCancelable(
false).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(getString(R.string.play_service_url)));
try {
startActivity(intent);
} catch (ActivityNotFoundException e0) {
intent.setData(Uri.parse(getString(R.string.play_service_web)));
try {
startActivity(intent);
} catch (Exception e1) {
//Ignore now.
}
} finally {
finish();
}
}
}).create().show();
}
}
我的应用说:
Google play services is not available. this application will close
我使用的代码是https://github.com/googleplus/gplus-quickstart-android
有什么建议吗?
不清楚您是否在检查设备上是否安装了 GooglePlayServices。我没有在您链接的代码中看到检查。
This webpage describes how to verify that GooglePlayServices is installed on a device and how to handle failures. The information is not completely current, but still provides a good outline of the processing. The GooglePlayServicesUtil class 提供检查是否安装了 PlayServices 的方法,如果缺少,则显示一个对话框以允许用户安装它。
部分代码来自网页:
private boolean checkPlayServices() {
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (status != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
showErrorDialog(status);
} else {
Toast.makeText(this, "This device is not supported.",
Toast.LENGTH_LONG).show();
finish();
}
return false;
}
return true;
}
private int REQUEST_CODE = 1234;
private void showErrorDialog(int code) {
GooglePlayServicesUtil.getErrorDialog(code, this, REQUEST_CODE).show();
}
我在这里玩一些代码给你建议:
strings.xml:
<string name="lbl_play_service">This application needs Google Play Service, you must install it first.</string>
<string name="play_service_url">market://details?id=com.google.android.gms</string>
<string name="play_service_web">https://play.google.com/store/apps/details?id=com.google.android.gms</string>
Some javas:
@Override
protected void onResume() {
super.onResume();
checkPlayService();
}
/**
* To confirm whether the validation of the Play-service of Google Inc.
*/
private void checkPlayService() {
final int isFound = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (isFound == ConnectionResult.SUCCESS) {
//Device has updated version of play-service.
} else {
//You need to store to update play-service.
new Builder(this).setTitle(R.string.application_name).setMessage(R.string.lbl_play_service).setCancelable(
false).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(getString(R.string.play_service_url)));
try {
startActivity(intent);
} catch (ActivityNotFoundException e0) {
intent.setData(Uri.parse(getString(R.string.play_service_web)));
try {
startActivity(intent);
} catch (Exception e1) {
//Ignore now.
}
} finally {
finish();
}
}
}).create().show();
}
}