Accesing google drive API for a specific account

雨燕双飞 提交于 2019-12-02 08:34:09

It is my belief that you can only use accounts (xxx@gmail.com) that are 'registered' on your device (Settings.. Accounts). That means, you have to invoke the Android account picker activity to let the user register the account (it would be a security disaster if your app could access any account only knowing it's email - no password, right?).

If you want to dig into the code that does it, just follow the 'REQ_ACCPICK' constant in this code. It shows you the sequence you have to use. Especially:

  • Account picker is invoked if the app does not have 'default email' to work with (GDAA.init() failed).
  • Account picker is invoked by the user from the app's menu so the user can select / add a new account (onOptionsItemSelected()).

It should be noted, that a similar account picker is invoked by GDAA's 'GoogleApiClient.Builder()' (your code above) if you do not pass any email. I believe there is a method somewhere that resets your 'serviceClient', allowing the GDAA builder to re-invoke the account picker again (see clearDefaultAccountAndReconnect()).
I have never used this approach, you may investigate this path further. I think I did not follow this, since I could not retrieve the current account selected by the user. And the knowledge of who the current user is was essential for my application (caching account specific data, etc...)

Good Luck

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!