检索帐户名称与新谷歌驱动器API驱动器、帐户、名称、新谷歌

2023-09-07 01:26:29 作者:何以安生

我设置的授权过程在 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.

推荐答案

我假设你已经有了快速入门或演示,或类似的东西了,而运行的,所以我将把这些两个例子。在 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.

 
精彩推荐
图片推荐