4

In my android application I have used Google drive to pick images and files, for files my code is working perfectly most of the time. Unfortunately in some cases image import is not working, image bitmap is returning null value, below is the code which I have used to convert content URI to input stream and bitmap.

Bitmap bitmap = null;
InputStream input = null;
try {
    input = getActivity()
        .getContentResolver()
        .openInputStream(
            Uri.parse("content://com.google.android.apps.docs.storage/document/acc%3D2%3Bdoc%3D83"));

    Log.Logger()
        .finest("Profileimagefile Fragment Drive called input" + input);

    bitmap = BitmapFactory
        .decodeStream(input);
} catch (FileNotFoundException e) {

    e.printStackTrace();
}

I have mentioned the URI which is not working, kindly help me to figure out the issue.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Madhu
  • 1,780
  • 23
  • 47

1 Answers1

2

Try this out to get the bitmap from an:

Uri sArtworkUri = Uri
    .parse("content://com.google.android.apps.docs.storage/document/acc%3D2%3Bdoc%3D83");
Uri uris = ContentUris.withAppendedId(sArtworkUri,
    Long.parseLong(fileUri));

ContentResolver res = getContentResolver();
InputStream in = null;
try { in = res.openInputStream(uris);
} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
Bitmap artwork = BitmapFactory.decodeStream( in );

Use this artwork ....

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Quick learner
  • 10,632
  • 4
  • 45
  • 55