5

I want to upload a photo from my camera directly into a drive folder:

OutputStream outputStream = result.getDriveContents().getOutputStream();
                    ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
/* image is my Bitmap */
                    image.compress(Bitmap.CompressFormat.PNG, 100, bitmapStream);

                    try {
                        outputStream.write(bitmapStream.toByteArray());
                    } catch (IOException e1) {
                        Log.i(TAG, "Unable to write file contents.");
                    }

So im doing this and it's working. The problem is that my pictures in drive is in very low quality and i need to have a High Quality video.

I already tried this solution Converting bitmap to byteArray android

But then in Drive the photo wasnt recognize as media file and can't read it. I may have failed something.

EDIT: i've done exactly the same things that is there https://stackoverflow.com/a/13000774/6644403 and doing this way to get my Bitmap in ActivityResult :

try {
                    mBitmapToSave = MediaStore.Images.Media.getBitmap(this.getContentResolver(), data.getData());
                } catch (IOException e) {
                    e.printStackTrace();
                }
Community
  • 1
  • 1
Hugo Houyez
  • 470
  • 3
  • 19
  • You might want to supply a uri for the output image, as discussed in this SO [question](http://stackoverflow.com/a/10272781/5995040). If the `uri` is not supplied, the camera intent will return only a thumbnail of the picture. You can also check this tutorial - [Take Picture in Android](http://www.tutorialforandroid.com/2010/10/take-picture-in-android-with.html), to see how the implementation on how to do this properly. Hope this helps. – Mr.Rebot Oct 11 '16 at 09:08
  • I've tried that but dont know why i didnt find a way to get the bitmap after all. When i try to specify uri, i cant retrieve my full size picture – Hugo Houyez Oct 12 '16 at 08:51

2 Answers2

1

I wasnt asking for rights to WRITE_EXTERNAL_STORAGE, it was in my manifest but since api23 i need to explicit and ask if the user ok.

Now it's good.

Hugo Houyez
  • 470
  • 3
  • 19
1

For Get Actual Image predefined path of Captured Image using

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
this.startActivityForResult(cameraIntent, 101);  

After Captured Image you can get Captured Image on path which is set in cameraIntent. If you don't Want to set predefined path then check Intent data.

    if (resultCode == android.app.Activity.RESULT_OK && requestCode == 101) {
        try {        
            path_mm = "Onsuccess_resultcode";
            generateNoteOnSD("photo34.txt", path_mm);
            Bitmap photo = null;
            if (data == null) {
                        //get Bitmap  here.
            } else {
               Uri u1 = data.getData();
               //get uri and find actual path on that uri.
               }
           }catch(Exception ex) {}
}

Refer this link Upload large files to Google Drive using GD API for google drive Uploadation.

Community
  • 1
  • 1
MIkka Marmik
  • 1,101
  • 11
  • 29