Skip to content Skip to sidebar Skip to footer

Bitmapfactory.decodefile() Returns Null In Some Devices

I'm using following code from here. I want to compress image. BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; Bitmap bmp = BitmapFa

Solution 1:

Tv 2) /raw//storage/emulated/0/mb/1511172993547.jpg

That is not a path you would get if the user selected pictures from Gallery or Photos. And certainly it is no file system path you could use for .decodeFile(). How did you obtain it?

3) /2/1/content://media/external/images/media/11647/ORIGINAL/NONE/486073582

That is no valid content scheme path. How did you obtain it? And certainly cannot be used for .decodeFile().

  i'm getting different typeof paths 

You will never get such paths if you 'act normal'. So what is it what you are doing? Elementary uri handling wrong?

using following code from here. 

That is pretty dirty example code for a big part as you have perceived now.

any way to compress image in all types of devices and OS versions.

Of course. Just use the obtained selected uri directly. Open an InputStream for it and use .decodeStream() instead.

My god.. you are not using the uri directly.

BitmapcmpBitmap= ImageUtils.compressUriQuality(OpenWallWeb.this, imgUri);

Change to

  Bitmap cmpBitmap = ImageUtils.compressUriQuality(OpenWallWeb.this, data.getData());

Solution 2:

I had same issue, please add storage permission to your app.

Check this link for more info

Storage permission error in Marshmallow

Post a Comment for "Bitmapfactory.decodefile() Returns Null In Some Devices"