Google Drive image upload from android -
i trying upload image google drive using api. ve searched didn't find way. ve got demo code uploads text file , works. need change upload image. code...
public void createfileongoogledrive(drivecontentsresult result){ final drivecontents drivecontents = result.getdrivecontents(); // perform i/o off ui thread. new thread() { @override public void run() { // write content drivecontents outputstream outputstream = drivecontents.getoutputstream(); writer writer = new outputstreamwriter(outputstream); try { writer.write("hello abhay!"); writer.close(); } catch (ioexception e) { log.e(tag, e.getmessage()); } metadatachangeset changeset = new metadatachangeset.builder() .settitle("abhaytest2") .setmimetype("text/plain") .setstarred(true).build(); // create file in root folder drive.driveapi.getrootfolder(mgoogleapiclient) .createfile(mgoogleapiclient, changeset, drivecontents) .setresultcallback(filecallback); } }.start(); }
how can change code upload image file.(by given location of image in device).? ve found few tutorials deprecated methods.
use code upload image google drive...
new thread() { @override public void run() { // write content drivecontents outputstream outputstream = drivecontents.getoutputstream(); // write bitmap data it. metadatachangeset metadatachangeset = new metadatachangeset.builder() .setmimetype("image/jpeg").settitle(title) .build(); bitmap image = bitmapfactory.decodefile(location)); bytearrayoutputstream bitmapstream = new bytearrayoutputstream(); image.compress(bitmap.compressformat.jpeg, 80, bitmapstream); try { outputstream.write(bitmapstream.tobytearray()); } catch (ioexception e1) { log.i("e", "unable write file contents."); } image.recycle(); outputstream = null; string title = "noisy"; log.i("e", "creating new pic on drive (" + title + ")"); drive.driveapi.getfolder(mgoogleapiclient,driveid) .createfile(mgoogleapiclient, metadatachangeset, drivecontents) .setresultcallback(filecallback); } }.start();
Comments
Post a Comment