android - How to get progress of a file being downloaded from google drive using REST API? -


i'm using this method download file google drive.

my code:

        bytearrayoutputstream bytearrayoutputstream = new bytearrayoutputstream();         driveservice.files().export(remotefiles[0].getid(),"text/plain").executemediaanddownloadto(bytearrayoutputstream);           fileoutputstream fileoutputstream= new fileoutputstream(new file(downloadsdirectory,remotefiles[0].getname()));           bytearrayoutputstream.writeto(fileoutputstream);          bytearrayoutputstream.flush();          bytearrayoutputstream.close();         fileoutputstream.close(); 

is there way progress of file download?

answering own question,found on page.

//custom listener download progress class downloadprogresslistener implements mediahttpdownloaderprogresslistener{       @override     public void progresschanged(mediahttpdownloader downloader) throws ioexception {         switch (downloader.getdownloadstate()){              //called when file still downloading             //only called after chunk has downloaded,so set appropriate chunk size             case media_in_progress:                 //add code showing progress                 break;             //called after download complete             case media_complete:                 //add code download completion                 break;          }     } }   //create drive.files.get object, //set progresslistener //change chunksize(default chunksize seems absurdly high) drive.files.get request = driveservice.files().get(remotefiles[0].getid()); request.getmediahttpdownloader().setprogresslistener(new downloadprogresslistener()).setchunksize(1000000); request.executemediaanddownloadto(outputstream); 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -