0

我成功设置了缩略图

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

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

但是在另一个活动中(我使用意图传输),当我从 Google Drive 列出文件夹时,file.getThumbnail() 始终为空(再次使用方法 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 : -获取文件 -文件资源

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

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

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;
    }
}
4

1 回答 1

0

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

于 2013-07-18T20:14:26.883 回答