Basically, I have been using this guide: https://developers.google.com/drive/android/intro
I have gotten the picture to upload into drive with the help of: https://github.com/googledrive/android-demos/tree/master/src/com/google/android/gms/drive/sample/demo
However, the GitHub project linked above does not provide any way to retrieve Images from Drive, it only shows text files. I am aware of the QueryNonTextFilesActivity.java but this gives the result in MetaDataBuffer which is appended onto ResultsAdapter. My question is: how do I use this data and convert to images (.png)?
Thank You
答案 0 :(得分:5)
假设您在插入图片后有DriveId,则可以使用Drive.DriveApi.getFile()检索文件 - 这会返回DriveFile。
获得DriveFile
后,您可以使用open()和代码(例如
InputStream
作为位图
file.open(mGoogleApiClient, DriveFile.MODE_READ_ONLY, null)
.setResultCallback(
new ResultCallback<DriveApi.DriveContentsResult>() {
@Override
public void onResult(DriveApi.DriveContentsResult result) {
if (!result.getStatus().isSuccess()) {
// Handle an error
}
DriveContents driveContents = result.getDriveContents();
InputStream is = driveContents.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(is);
// Do something with the bitmap
// Don't forget to close the InputStream
is.close();
});