问题描述
下面的2 code片段展示我遇到了与新的谷歌云端硬盘Android API的问题/谷歌播放服务4.2(libver 15)。抑或是一个功能,我不知道?所有的错误检查和初始化,以保持code简单的被删除。
The following 2 code snippets demonstrate the problem I ran into with the NEW Google Drive Android API / Google Play Services 4.2 (libver 15). Or is it a feature I don't know about? All error checking and initialization is removed in order to keep the code simple.
1 / I制造形象/ JPEGMIME类型的图片;
1/ I create a picture of "image/jpeg" MIME type;
GoogleApiClient mGAC;
byte[] jpgBuffer;
DriveFolder fldr;
ContentsResult rslt = Drive.DriveApi.newContents(mGAC).await();
Contents cont = rslt.getContents();
cont.getOutputStream().write(jpgBuffer);
MetadataChangeSet meta = new MetadataChangeSet.Builder()
.setTitle("foo.jpg").setMimeType("image/jpeg")
.build();
fldr.createFile(mGAC, meta, cont);
一切都在驱动器很好,很正常。图片是存在的,看起来棒极了,我甚至可以将其发送给我的妈妈。但是,这不是我后。我想在我的Android应用程序的其他部分进行检索。
Everything is nice and dandy in the Drive. Image is there, looking great, I can even send it to my mom. But this is not what I'm after. I would like to retrieve it in another part of my Android app.
2 /所以我试试这个:
2/ So I try this:
Query query = new Query.Builder().addFilter(
Filters.eq(SearchableField.MIME_TYPE, "image/jpeg")
).build();
MetadataBufferResult rslt = Drive.DriveApi.query(mGAC, query).await();
for (Metadata md : rslt.getMetadataBuffer()) {
Log.d("TAG", md.getTitle() + " " + md.getMimeType());
}
结果:大又肥罢了。
Result: big, fat NOTHING.
我不会放弃的,所以下一个合乎逻辑的步骤是寻找任何文件。和文件foo.jpg我保存在步骤1 /正显示出图像/ PNGMIME类型。
I'm not giving up, so the next logical step is to look for ANY file. And the file "foo.jpg" I saved in step 1/ is showing as "image/png" MIME type.
推荐答案
谜团解开。 这是一个功能!的jpgBuffer在
Mystery is solved. IT IS A FEATURE! The "jpgBuffer" in
cont.getOutputStream().write(jpgBuffer);
实际上包含PNG二进制数据。所以,即使我的应用程序指定的图像/ JPEGMIME类型,谷歌通过我的(我的用户)的数据探测后决定正确的MIME类型为图像/ PNG。还应当指出的是,它与一些延迟发生,使得调试过程更加神秘
actually contains PNG binary data. So even if my app specified "image/jpeg" MIME type, Google after snooping through my (my user's) data decided to correct MIME type to "image/png". It should also be noted that it happens with some delay, making the debugging process even more mysterious.
这篇关于图像/ JPEG" MIME类型从&QUOT切换;到"图像/ PNG"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!