final private ResultCallback driveContentsCallback = new
ResultCallback() {
@Override
public void onResult(DriveApi.DriveContentsResult result) {
if (!result.getStatus().isSuccess()) {
showMessage("Error while trying to create new file contents");
return;
}
final DriveContents driveContents = result.getDriveContents();
// Perform I/O off the UI thread.
new Thread() {
@Override
public void run() {
// write content to DriveContents
int a;
String sdcard = Environment.getExternalStorageDirectory().getPath();
File myFile = new File(sdcard+"/payment.pdf");
try {
FileInputStream fin;
BufferedReader br;
fin=new FileInputStream(myFile);
br = new BufferedReader(
new InputStreamReader(fin));
OutputStream outputStream = driveContents.getOutputStream();
ByteArrayOutputStream byt = new ByteArrayOutputStream();
Writer writer = new OutputStreamWriter(outputStream);
while((a=br.read())!=-1)
{
byt.write(a);
}
outputStream.write(byt.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle("New file pdf2")
.setMimeType("application/pdf")
.setStarred(true).build();
// create a file on root folder
Drive.DriveApi.getRootFolder(getGoogleApiClient())
.createFile(getGoogleApiClient(), changeSet, driveContents)
.setResultCallback(fileCallback);
}
}.start();
}
};
final private ResultCallback driveContentsCallback = new
ResultCallback() {
@Override
public void onResult(DriveApi.DriveContentsResult result) {
if (!result.getStatus().isSuccess()) {
showMessage("Error while trying to create new file contents");
return;
}
final DriveContents driveContents = result.getDriveContents();