简体   繁体   English

Google云端硬盘帐户选择器onActivityResult resultCode始终为-1

[英]Google Drive Account Picker onActivityResult resultCode is always -1

I am currently working on an android application and I am trying to integrate Google Drive. 我目前正在开发一个android应用程序,并且正在尝试集成Google云端硬盘。 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. 我在帐户选择器中遇到问题,当选择了帐户并将其返回到onActivityResult函数时,resultCode为-1,我认为应该为0表示成功。

Below is how I am opening the account picker 下面是我如何打开帐户选择器

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

credential is a global variable so the whole class has access to this variable. credential是全局变量,因此整个类都可以访问此变量。

Below is the code for the onActivityResult 以下是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();
    }
}

It goes into the else if statement fine but when it checks if the resultCode equals RESULT_OK it returns false as the resultCode is for some reason being set to -1. 它将进入else if语句,但是当它检查resultCode是否等于RESULT_OK时,由于由于某种原因将resultCode设置为-1,因此它将返回false。 I assume -1 means that something has failed but I can't see any error messages in the logCat. 我假设-1表示发生了某些故障,但在logCat中看不到任何错误消息。

Thanks for any help you can provide. 感谢您的任何帮助,您可以提供。

Go through this : value of RESULT_OK is -1 . 请执行以下操作RESULT_OK值为-1

0 is for RESULT_CANCELLED 0代表RESULT_CANCELLED

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM