2

我目前正在开发一个 android 应用程序,并且正在尝试集成 Google Drive。I'm having a problem with the account picker, that when the account is chosen and it returns into the onActivityResult function the resultCode is -1 which I believe it should be 0 to mean that it was successful.

以下是我打开帐户选择器的方式

credential = GoogleAccountCredential.usingOAuth2(context, DriveScopes.DRIVE);
startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER

credential是一个全局变量,所以整个类都可以访问这个变量。

下面是 onActivityResult 的代码

else if (resultCode == REQUEST_ACCOUNT_PICKER)
{
    if (resultCode == RESULT_OK && intent != null && intent.getExtras() != null)
    {
    String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
    SharedPreferences settings = context.getSharedPreferences("prefs", 0);
    SharedPreferences.Editor editor = settings.edit();
    editor.putString("google_drive_account_name", accountName);
    editor.putBoolean("drive_sync_upload_download_required", true);
    editor.commit();
    }
}

它进入 else if 语句很好,但是当它检查 resultCode 是否等于 RESULT_OK 时,它返回 false,因为 resultCode 由于某种原因被设置为 -1。我假设 -1 表示某些事情发生了故障,但我在 logCat 中看不到任何错误消息。

感谢您的任何帮助,您可以提供。

4

1 回答 1

1

通过这个: 的值RESULT_OK-1

0是为了RESULT_CANCELLED

于 2013-03-23T16:28:04.150 回答