googleworkspace / android-samples

Android samples for Google Workspace APIs
Apache License 2.0
636 stars 410 forks source link

Cant create pdf files #25

Closed pratikbh closed 9 years ago

pratikbh commented 9 years ago

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();
            }
        };
Mohindharan commented 7 years ago

I'm getting a blank PDF