2016-01-17 72 views
0

簽訂我與谷歌雲端硬盤API工作,現在我有簡單的應用程序(類似於https://github.com/googledrive/android-quickstart),但我想有兩個選項添加登錄頁面(登錄與谷歌驅動器和登錄爲來賓)顯示僅當用戶未使用任何帳戶登錄時。我如何檢查它?我想僅在點擊「使用谷歌驅動器登錄」後才顯示此活動。我會看到要選擇的帳戶列表的對話框。谷歌雲端硬盤API檢查,如果用戶在

回答

0

上有谷歌驅動器中沒有「客戶」登錄。只有賬戶「註冊」在Android設備上(請參閱設置>帳戶)可以訪問該驅動器(其GooDrives)。

有2種方法來處理帳戶創建/採摘。

1 /你不指定有效的(設備上註冊)帳戶的電子郵件

GoogleApiClient GAC = new GoogleApiClient.Builder(context) 
    //.setAccountName(email) 
    .addApi(Drive.API) 
    .addScope(Drive.SCOPE_FILE) 
    .addConnectionCallbacks(...) 
    .addOnConnectionFailedListener(...) 
    .build(); 

和GooPlaySvcs會彈出帳號選擇對話框,允許用戶選擇一個有效的帳戶或創建一個新的。您的應用程序不會知道用戶選擇/創建的帳戶。

2 /你指定有效(註冊您的設備)帳戶的電子郵件

GoogleApiClient GAC = new GoogleApiClient.Builder(context) 
    .setAccountName(email) 
    .addApi(Drive.API) 
    .addScope(Drive.SCOPE_FILE) 
    .addConnectionCallbacks(...) 
    .addOnConnectionFailedListener(...) 
    .build(); 

現在,你怎麼弄的email?你不能指定一個任意的電子郵件。同樣,你必須通過account picker使用該設備的註冊者之一:

<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
... 
static final int REQ_ACCPICK = 999; 
... 
startActivityForResult(AccountPicker.newChooseAccountIntent(null, null, 
    new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, true, null, null, null, null), REQ_ACCPICK); 
... 
@Override 
protected void onActivityResult(int request, int rslt, Intent data) { 
    if (
    request == REQ_ACCPICK && 
    rslt == RESULT_OK && 
    data != null && data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME) != null 
) 
    email = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); 
    ... 

請看到這個典型的處理在此codeREQ_ACCPICK。您必須添加一個客戶經理(如上述演示中的UT.AM類)並堅持當前帳戶的電子郵件。

好運

+0

我知道Google雲端硬盤上沒有'guest'登錄信息。我想要有兩個選擇:登錄谷歌驅動器或工作作爲客人(沒有谷歌驅動器功能),所以我必須顯示這個選項,只有當用戶從谷歌註銷(我不會看到帳戶選擇器後點擊第一個選項)。我只需要知道用戶是否登錄。具有持久性(選項#2)在[GDAA] – Giks91

+0

應用的私人客戶經理(https://developers.google.com/drive/android/intro)。或者,(在[REST Api](https://developers.google.com/drive/v3/web/about-sdk))下,您可以使用GoogleAccountCredential.usingOAuth2(...)。setSelectedAccountName(email)/ getSelectedAccount ()。兩者都需要'GET_ACCOUNTS'權限。 – seanpj

相關問題