检索帐户名称与新谷歌驱动器API [英] Retrieve account name with the NEW Google Drive API

查看:137
本文介绍了检索帐户名称与新谷歌驱动器API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置的授权过程在 https://developers.google所描述的谷歌播放服务.COM /驱动器/安卓/ AUTH

现在用户已授权的应用程序,我想检索的帐户名称。但我不能找到API中的任何方法( http://developer.android.com /reference/gms-packages.html ),这将是有益的。

Now that the user has authorized the app I want to retrieve the account name. But I can't find any method in the API (http://developer.android.com/reference/gms-packages.html) that would be helpful.

推荐答案

我假设你已经有了快速入门演示,或类似的东西了,而运行的,所以我将把这些两个例子。在<一个href="https://github.com/googledrive/android-demos/blob/master/src/com/google/android/gms/drive/sample/demo/BaseDemoActivity.java"相对=nofollow> BaseDemoActivity.java code,你会发现,账户选择调用连接失败时,

I assume that you already have QUICKSTART or DEMO, or something similar up-and-running, so I will refer to these 2 examples. In the BaseDemoActivity.java code, you'll notice that account selection is invoked when connection fails,

@Override public void onConnectionFailed(ConnectionResult result) {
  ...
  result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
  ...
}

...它回来的onActivityResult()。我只是抓住了意图数据,并获得KEY_ACCOUNT_NAME,这是选择的电子邮件。在code以下是从DEMO的BaseDemoActivity.java修改(我上面提到)。

... and it comes back in onActivityResult(). I just grab the intent data and get the KEY_ACCOUNT_NAME, it is the selected email. The code below is modified from the DEMO's BaseDemoActivity.java (I mentioned above).

@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
  switch (requestCode) {
    case REQUEST_CODE_RESOLUTION:
    if ((resultCode == RESULT_OK) && (data != null) && (data.getExtras() != null ))
      // user selected account, get it
      String email = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
    else
      finish();    // user cancelled selection, an easy solution
    break;
  }

希望它帮助。

Hope it helps.

这篇关于检索帐户名称与新谷歌驱动器API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆