我可以從谷歌驅動器獲取文件的驅動器ID。 通過以下代碼。如何獲取谷歌驅動器的文件的URL在Android下載
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,這樣我可以通過URL使用此LINK
您是否嘗試過使用file.getDownloadUrl()? 「 –
」getDownloadUrl()「沒有這樣的方法@ BidhanA – kkkk
你能給我一個你得到的driveId的例子嗎?打印driveId.getResourceId()時會得到什麼? –