0

I am trying to retrieve the images from Mediastore.Images.Media I am always getting the cursor to be null. Please suggest how to solve the issue. Thanks in advance

Uri contenturi = Images.Media.getContentUri("phoneStorage");
    String[] mprojection = { MediaStore.Images.Media.DATA };
    String mselection = null;
    String[] mselectionArgs = null;
    String msortOrder ="date_added DESC";
    Cursor mcursor = managedQuery(contenturi, mprojection, mselection, mselectionArgs, msortOrder);

When I am checking it says the mcursor to be null, I have tried changing the uri to external storage also tried with no sort order. But still its returning null. Please help

piokuc
  • 25,594
  • 11
  • 72
  • 102
Saransh Mohapatra
  • 9,430
  • 10
  • 39
  • 50

1 Answers1

0

buddy try this code,

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);    
startActivityForResult(Intent.createChooser(intent,getResources().getString(R.string.accept)),1);

Now just use onActivityResult method to get image from Gallery.

Ronak Mehta
  • 5,971
  • 5
  • 42
  • 69