Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
新的驱动器Api连接和授权不在Android上工作_Android_Google Drive Api_Google Authentication_Google Drive Android Api - Fatal编程技术网

新的驱动器Api连接和授权不在Android上工作

新的驱动器Api连接和授权不在Android上工作,android,google-drive-api,google-authentication,google-drive-android-api,Android,Google Drive Api,Google Authentication,Google Drive Android Api,我按照以下步骤在我的应用程序(Google Drive Android API)中登录驱动器: 我使用debug.keystore生成了SHA1指纹。当我在我的设备上运行应用程序时,第一次连接失败,但hasResolution为true,并显示“帐户选择”对话框。问题是,在我选择帐户之前,onActivityResult方法会立即被调用,当然,结果代码是不正确的 private GoogleApiClient mGoogleApiClient; @Override protected voi

我按照以下步骤在我的应用程序(Google Drive Android API)中登录驱动器:

我使用debug.keystore生成了SHA1指纹。当我在我的设备上运行应用程序时,第一次连接失败,但hasResolution为true,并显示“帐户选择”对话框。问题是,在我选择帐户之前,onActivityResult方法会立即被调用,当然,结果代码是不正确的

private GoogleApiClient mGoogleApiClient;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //some other code...

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Drive.API)
            .addScope(Drive.SCOPE_FILE)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
}

@Override
protected void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
}

@Override
protected void onStop() {
    if(mGoogleApiClient != null)
        mGoogleApiClient.disconnect();
    super.onStop();
}

@Override
public void onConnected(Bundle bundle) {
    Log.d(TAG, "DRIVE: connected");
    CONNECTED = true;
}

@Override
public void onConnectionSuspended(int i) {
    Log.d(TAG, "DRIVE: disconnected");
    CONNECTED = false;
}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    Log.d(TAG, "DRIVE: connection failed");
    CONNECTED = false;

    if (connectionResult.hasResolution()) {
        try {
            connectionResult.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
        } catch (IntentSender.SendIntentException e) {
            //mGoogleApiClient.connect(); whit or whitout is the same...
        }
    } else {
        GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
    }
}

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data){
    switch (requestCode) {
        case REQUEST_CODE_RESOLUTION:
            if (resultCode == RESULT_OK) {
                mGoogleApiClient.connect();
            }
            break;
        case REQUEST_CODE_CREATOR:
            if(resultCode != RESULT_OK)
                newNotification("Upload Fallito", "...", android.R.drawable.ic_dialog_alert);
            break;

    }
}

由于没有时间来分析这里出了什么问题,我建议你抓住它并试一试。不漂亮,但小巧实用。授权迷宫在自述中被触及。但我不知道你的环境,所以可能没用

如果这是现在正在发生的事情,谷歌驱动器/闲逛/谈话已经停止了大约2个小时(至少在纽约这里),这将解释为什么它会立即从远处失败,代码看起来没有任何问题。我不明白为什么会立即调用“onActivityResult方法”。当用户在“AccountManager.KEY\u account\u NAME”(离开/返回时通过onStop(),onStart())中选择的电子邮件点击OK后,它应该会从帐户选择器返回。请尝试将您的
mgoogleapclient.connect()
从onStart()移动到onResume()。我尝试了您的一段代码。。。我在OnConnectionFailed中插入AccountPicker和startActivityForResult,但结果相同。立即调用OnActivityResult为什么不尝试以下操作:1/剪切并保存启动活动代码2/将完整的MainActivity类粘贴到那里(我提到的示例中的所有内容),只保留“包”名称。3/将MainActivity类重命名为在4/之前调用的启动活动的名称/如果不希望触动驱动器,请注释掉“new DoStuffAsync(this).execute();”在onConnected()中。如果我看不到周围的环境,我很难分析你的一小部分代码。此外,您的问题看起来与驱动器API无关,看起来像是逻辑流问题。我没有导入到项目com.google.API中,因为我认为它只能通过包Play服务中提供的类来处理与google Drive的连接。连接以前使用旧API工作,我遇到的问题与新过程有关。