从Google云端硬盘列出文件时,缩略图图片为空

时间:2013-07-18 10:35:52

标签: android google-drive-api

I set the thumbnail successfull

在同一项活动中,我使用以下代码获取与文件相关的信息, file.getThumbnail()显示编码数据,您知道。

private static void printFile(Drive service, File file) {
    System.out.println("Title: " + file.getTitle());
    System.out.println("getThumbnail: " + file.getThumbnail());
}

但在另一项活动中(我使用意图传输),当我从Google云端硬盘列出文件夹时,file.getThumbnail()始终为null (使用方法printFile()再次)。 我不知道为什么? 以下代码用于列出指定文件夹中的文件,成功:

private void listFile(final Drive service, final String folderId) {
    new Thread(new Runnable() {

        @Override
        public void run() {
            Files.List request;
            try {
                request = service.files().list();
                // Set id of the specified folder
                request.setQ(folderId);
                do {
                    try {
                        FileList fileList = request.execute();
                        request.setPageToken(fileList.getNextPageToken());

                        // Implement : get list of files
                        for (File file : fileList.getItems()) {
                            printFile(service, file);

                            // TODO Get thumb nail in here
                            InputStream is = 
                                    downloadThumbnailFile(ManageFileDriveActivity.mDriveService, file); 
                             // We don't need note this method, because file.getThumnail() currently is null                            
                        }
                    } catch (final IOException e) {
                        request.setPageToken(null);
                    }
                } while (request.getPageToken() != null
                        && request.getPageToken().length() > 0);
            } catch (final IOException e1) {
            }
        }
    }).start();
}

p / s: - Get file - File resource

请告诉我如何让拇指指甲图像成功。 谢谢!

更新 使用以下代码,这是一个很好的解决方案:

public static InputStream downloadThumbnailFile(Drive service, File file)
        throws IOException {
    if (file.getThumbnailLink() != null && !file.getThumbnailLink().isEmpty()) {
        try {
            System.out.println("getThumbnailLink: " + file.getThumbnailLink());
            HttpResponse resp = service.getRequestFactory()
                    .buildGetRequest(new GenericUrl(file.getThumbnailLink()))
                    .execute();

            return resp.getContent();
        } catch (IOException e) {
            // An error occurred.
            e.printStackTrace();
            return null;
        }
    } else {
        // The file doesn't have any content stored on Drive.
        return null;
    }
}

1 个答案:

答案 0 :(得分:0)

使用file.getThumbnailLink()thumbnail属性是只写的。