1

Im having problem in my code in KITKAT OS. I want to get/display an image from gallery and decode it if its a higher size and its working fine for API lower than 19. But when I tried my app in KITKAT, I always get a null pointer exception because it returned.

content://com.android.providers.media.documents/document/image:62

I already look for solutions and found this.

input = context.getContentResolver().openInputStream(selectedImage);
bmp = BitmapFactory.decodeStream(input);

Its displaying the image but I'm missing one more step, that is to decode it since i cant get the exact file path of the image.

Bitmap imgbitmap = BitmapFactory.decodeFile(filepath, options_for_not_toobig);

How would I get the exact address of the image in KITKAT or how other way in decoding an image.

thanks

user4144348
  • 313
  • 3
  • 8

2 Answers2

0

Try this code if Android version is kitkat:

ParcelFileDescriptor parcelFileDescriptor = getContentResolver().openFileDescriptor(uri, "r");         
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
bitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor);
parcelFileDescriptor.close();

Go through this link - https://developer.android.com/guide/topics/providers/document-provider.html

AJPerez
  • 3,435
  • 10
  • 61
  • 91
0

I've posted a answer in another post where similar issue is lifted. There youll find the method for getting the path in KitKat. File Upload in WebView

Community
  • 1
  • 1
Deko
  • 1,028
  • 2
  • 15
  • 24