Android上的谷歌登录错误

Android上的谷歌登录错误,android,google-login,Android,Google Login,我的应用程序说: Google play服务不可用。此应用程序将关闭 我使用的代码是 有什么建议吗?不清楚您是否正在检查设备上是否安装了GooglePlayServices。我在你链接到的代码中没有看到复选框 描述如何验证设备上是否安装了GooglePlayServices以及如何处理故障。这些信息并不完全是最新的,但仍然提供了处理过程的良好轮廓。该类提供了一些方法,用于检查是否安装了PlayServices,并显示一个对话框,允许用户在缺少PlayServices时进行安装 网页中的部分代码:

我的应用程序说:

Google play服务不可用。此应用程序将关闭

我使用的代码是


有什么建议吗?

不清楚您是否正在检查设备上是否安装了GooglePlayServices。我在你链接到的代码中没有看到复选框

描述如何验证设备上是否安装了GooglePlayServices以及如何处理故障。这些信息并不完全是最新的,但仍然提供了处理过程的良好轮廓。该类提供了一些方法,用于检查是否安装了PlayServices,并显示一个对话框,允许用户在缺少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();
    }
}
strings.xml:
此应用程序需要Google Play服务,您必须先安装它。
market://details?id=com.google.android.gms
https://play.google.com/store/apps/details?id=com.google.android.gms
一些Java:
@凌驾
受保护的void onResume(){
super.onResume();
checkPlayService();
}
/**
*确认谷歌公司播放服务的验证。
*/
私有void checkPlayService(){
final int isFound=GooglePlayServicesUtil.isGooglePlayServicesAvailable(此);
if(isFound==ConnectionResult.SUCCESS){
//设备已更新播放服务的版本。
}否则{
//您需要存储以更新播放服务。
新建生成器(this).setTitle(R.string.application\u name).setMessage(R.string.lbl\u play\u service).setCancelable(
错误)。setPositiveButton(R.string.btn_是,新建DialogInterface.OnClickListener(){
public void onClick(对话框接口对话框,int whichButton){
dialog.dismise();
意向意向=新意向(意向.行动\视图);
setData(Uri.parse(getString(R.string.play\u service\u url));
试一试{
星触觉(意向);
}捕获(ActivityNotFoundException e0){
setData(Uri.parse(getString(R.string.play\u service\u web));
试一试{
星触觉(意向);
}捕获(异常e1){
//现在忽略。
}
}最后{
完成();
}
}
}).create().show();
}
}

您似乎正在尝试使用模拟器。试试真正的设备。后者肯定会安装Google Play服务。我正在一个设备中尝试:(你确定Google Play服务安装在那里吗?在Desive中?我不知道,我怎么知道?如果它安装了Google Play store,那么你可以确定它们已安装。另外……你是否声明Google Play服务依赖于gradle文件?“new Builder”没有发现我复制了你的代码,IDE说“无法解析符号生成器”@christianrusso它生成了一个AlterDialogActivity生命周期方法
onStart()
onResume()
之前调用
connect()
,因此在
onStart()
之前调用它,它位于
onResume()
中。好的,此代码更改了我的错误。不,我有ConnectionResult。getErrorCode()=4我想是的。如果您在pastebin更新代码,我会查看它。