gpt4 book ai didi

android - 无法获取刚刚创建的文件的 DriveID 和 ResourceID

转载 作者:太空狗 更新时间:2023-10-29 15:06:29 25 4
gpt4 key购买 nike

我一直在按照 Google 的文档在 Google Drive 上创建一个文件夹,然后在其中创建一个 jpeg 文件。 How to create file

然后,我需要生成指向该文件的直接链接。我使用以下链接执行此操作:https://docs.google.com/uc?export=download&id=[File ResourceID]

文件在光盘上创建。我可以使用浏览器访问它。问题是,在 onCreateFile(DriveFolder.DriveFileResult driveFileResult) 回调或其他任何地方,我无法获得正确的 ResourceID。

private void saveFileToDrive(final Bitmap image) {
// Start by creating a new contents, and setting a callback.
Log.i(TAG, "Creating new contents.");
DriveApi.newContents(mGoogleApiClient).addResultCallback(new DriveApi.OnNewContentsCallback() {

@Override
public void onNewContents(final DriveApi.ContentsResult result) {
// If the operation was not successful, we cannot do anything
// and must fail.
if (!result.getStatus().isSuccess()) {
Log.i(TAG, "Failed to create new contents.");
return;
}
// Otherwise, we can write our data to the new contents.
Log.i(TAG, "New contents created. ID:"+result.getContents().getDriveId());
// Get an output stream for the contents.
OutputStream outputStream = result.getContents().getOutputStream();
// Write the bitmap data from it.
ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 100, bitmapStream);
try {
outputStream.write(bitmapStream.toByteArray());
} catch (IOException e1) {
Log.i(TAG, "Unable to write file contents.");
}
// Create the initial metadata - MIME type and title.
// Note that the user will be able to change the title later.
MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
.setMimeType("image/jpeg")
.setTitle(ds.getFujifilmOrderID()+".jpeg")
.build();

Drive.DriveApi.getFolder(mGoogleApiClient, PhotoPrintOrder.this.MyRealFontFolder).createFile(mGoogleApiClient, metadataChangeSet, result.getContents()).addResultCallback(new DriveFolder.OnCreateFileCallback() {
@Override
public void onCreateFile(DriveFolder.DriveFileResult driveFileResult) {
Log.d(TAG, "DriveID:"+driveFileResult.getDriveFile().getDriveId());
Log.d(TAG, "ResourceID:"+driveFileResult.getDriveFile().getDriveId().getResourceId());

}
});
}
});
}

输出是这样的:

DriveID:DriveId:CAESABiGAiCMlafg_VA=

ResourceID: null

如果我关闭应用程序然后再次启动它,将列出文件夹的内容,我会得到正确的值:

DriveID:CAESHDBCeXR3by1ta0hDQ0JXRzAyWjA5UFIzUmlha0UYhAIgjJWn4P1Q

ResourceID: 0Bytwo-mkHCCBWG02Z09PR3RiakE

我尝试重新连接 GoogleApiClient、driveFileResult.getDriveFile().commitAndCloseContents()、DriveApi.requestSync()。没有什么对我有用。

如果有任何可能的帮助,我将不胜感激。

最佳答案

requestSync 异步请求同步并立即返回。它不保证同步完成,并且在同步完成之前您不能拥有非空资源 ID。

关于android - 无法获取刚刚创建的文件的 DriveID 和 ResourceID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21533349/

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