gpt4 book ai didi

android - 如何获取要在android中下载的谷歌驱动器文件的url

转载 作者:行者123 更新时间:2023-11-29 00:10:40 24 4
gpt4 key购买 nike

我可以从谷歌驱动器中获取文件的驱动器 ID。通过以下代码。

import com.example.googledrivetest2.ProcessDownload.DownloadFileAsync;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.Result;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.drive.Drive;
import com.google.android.gms.drive.DriveApi;
import com.google.android.gms.drive.DriveApi.DriveContentsResult;
import com.google.android.gms.drive.DriveApi.DriveIdResult;
import com.google.android.gms.drive.DriveContents;
import com.google.android.gms.drive.DriveFile;
import com.google.android.gms.drive.DriveFolder;
import com.google.android.gms.drive.DriveFolder.DriveFileResult;
import com.google.android.gms.drive.DriveId;
import com.google.android.gms.drive.DriveResource;
import com.google.android.gms.drive.Metadata;
import com.google.android.gms.drive.MetadataChangeSet;
import com.google.android.gms.drive.OpenFileActivityBuilder;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i(TAG, "in onActivityResult() - triggered on pressing Select");

switch (requestCode) {

case REQUEST_CODE_SELECT:
if (resultCode == RESULT_OK) {
/*get the selected item's ID*/
DriveId driveId = (DriveId) data.getParcelableExtra(
OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);//this extra contains the drive id of the selected file
Log.i(TAG, "Selected folder's ID: " + driveId.encodeToString());
Log.i(TAG, "Selected folder's Resource ID: " + driveId.getResourceId());// this is the id of the actual file
Toast.makeText(getApplicationContext()," my id: "+driveId.getResourceId() , Toast.LENGTH_LONG).show();

DriveFile file = Drive.DriveApi.getFile(googleApiClient,driveId);
....
}
};

现在我想获取该文件的 URL,以便我可以使用此 LINK 传递 URL 进行下载

最佳答案

你试过这个方法了吗?

DriveFile file = Drive.DriveApi.getFile(googleApiClient,driveId);
MetadataResult mdRslt = file.getMetadata(googleApiClient).await();
if (mdRslt != null && mdRslt.getStatus().isSuccess()) {
String link = mdRslt.getMetadata().getWebContentLink();
Log.d("LINK", link);
}

关于android - 如何获取要在android中下载的谷歌驱动器文件的url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30421889/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com