我的應用程序說:錯誤登錄谷歌在Android上
谷歌播放服務不可用。這個應用程序將關閉
的代碼,我現在用的就是https://github.com/googleplus/gplus-quickstart-android
任何建議?
我的應用程序說:錯誤登錄谷歌在Android上
谷歌播放服務不可用。這個應用程序將關閉
的代碼,我現在用的就是https://github.com/googleplus/gplus-quickstart-android
任何建議?
目前還不清楚您是否正在檢查設備上是否安裝了GooglePlayServices。我沒有看到您鏈接的代碼中的支票。
This webpage介紹如何驗證GooglePlayServices是否安裝在設備上以及如何處理故障。這些信息並不完全是最新的,但仍然提供了一個很好的處理輪廓。 GooglePlayServicesUtil類提供了用於檢查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();
}
不工作,請檢查我的代碼:http://pastebin.com/RpvjEmKv –
活動生命週期方法'onStart()'在'onResume()'之前被調用。你在'onStart()'中調用'connect()',所以它在'onResume()'中的'checkPlayServices()'之前被調用。 –
好的,這段代碼改變了我的錯誤。不,我有ConnectionResult.getErrorCode()= 4 –
我在這裏玩的一些代碼,給你的建議:
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服務。 –
我試圖在一個設備:( –
您確定Google play服務安裝在那裏? –