使用新的 Google Drive API 检索帐户名称 [英] Retrieve account name with the NEW Google Drive API

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

问题描述

我按照 https://developers.google 中所述设置了 Google Play 服务的授权流程.com/drive/android/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.

推荐答案

我假设你已经有 QUICKSTARTDEMO,或类似的启动和运行的东西,所以我会参考这两个例子.在 BaseDemoActivity.java 代码,您会注意到连接失败时会调用帐户选择,

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,它是选定的电子邮件.下面的代码是从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;
  }

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

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