有2種方式validate帳戶authentication:
GoogleApiClient GAC = new GoogleApiClient.Builder(context) //.setAccountName(email) .addApi(Drive.API) .addScope(Drive.SCOPE_FILE) .addConnectionCallbacks(...) .addOnConnectionFailedListener(...) .build();
谷歌Play服務,會彈出account picker對話框,讓你選擇有效的帳戶或創建一個新帳戶。
GoogleApiClient GAC = new GoogleApiClient.Builder(context) .setAccountName(email) .addApi(Drive.API) .addScope(Drive.SCOPE_FILE) .addConnectionCallbacks(...) .addOnConnectionFailedListener(...) .build();
您必須通過帳戶選擇器來使用該設備的註冊者之一:
<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);
下面是一個示例演示應用程序其中討論require sccount pick
:https://github.com/seanpjanson/GDAADemo/blob/master/app/src/main/java/com/spjanson/gdaademo/MainActivity.java
良好的信息,但仍然不會工作,當我使用這樣的意圖 String VideoUrl =「https://drive.google.com/file/d/FILE_ID/view」; Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(videoUrl)); intent.setPackage(「com.google.android.apps.docs」); startActivity(intent); Google雲端硬盤應用會要求重新選擇一個帳戶 – Ragnar
如果您發現更好的答案,請將其發佈爲答案 –