-1

I am trying to select image from gallery and code is working well on devices upto andorid nogut(7). I have added provider.xml also. This is my code

   public void processSelectionOfImage(int code) {
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_PICK);

    Uri fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);

    try {
        intent.putExtra("return-data", true);
        startActivityForResult(
                Intent.createChooser(intent, "Select Picture"), code);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

I am getting NullPointerException

  java.lang.NullPointerException: file
    at android.net.Uri.fromFile(Uri.java:453)
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Android Coder
  • 11
  • 1
  • 8

1 Answers1

0

There is no inbuilt method getoutputmediafileuri() in android. It is a custom method someone write for getting file URI to store captured images in particular directory. You have to defined and put logic for it. Instead of that use this code,

   Intent imageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
   File imagesFolder = new File(Environment.getExternalStorageDirectory(),"MyImages");
   imagesFolder.mkdirs(); // <----
   File image = new File(imagesFolder, "image_001.jpg");
   Uri uriSavedImage = Uri.fromFile(image);
   imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
   startActivityForResult(imageIntent,0);
Aravind V
  • 358
  • 2
  • 10