简体   繁体   中英

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. 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.

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.

Below is the code for the 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. I assume -1 means that something has failed but I can't see any error messages in the logCat.

Thanks for any help you can provide.

Go through this : value of RESULT_OK is -1 .

0 is for RESULT_CANCELLED

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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