1

I am trying to open gallery on Nexus 7 with Android 6.0. It does not have in built gallery, but it does have the Google Photos app.

I am using the following code to open the gallery :

    Intent i = new intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Always show the chooser (if there are multiple options available)
    startActivityForResult(Intent.createChooser(i, "Select Picture"), PICK_IMAGE_REQUEST);

The above code works well in all the versions below 6.0. And Please note that I am already using RUN TIME PERMISSIONS for accessing gallery and have given the permission to access gallery / or externa storage.

Now when the code is executed, I get a transparent screen with heading "Select Picture" and in the middle a text No Apps can perform this action.

Now what do I do to pick or choose image and use in my app.

Any help is appreciated.

Thanks

dur
  • 15,689
  • 25
  • 79
  • 125
intellignt_idiot
  • 1,962
  • 2
  • 16
  • 23
  • Sorry, I just edited my code. I just want to start i. Actually , I am using this code , so that only gallery opens and not any other option to pick image. – intellignt_idiot May 07 '16 at 09:07

3 Answers3

1

I am using the following code to open the gallery

That code has nothing to do with a "gallery". That code is requesting to pick a piece of content from a particular collection of content. There may be zero, one, or several activities on the device that offer to support that Intent structure.

The above code works well in all the versions below 6.0

Only on devices that happen to have one or more activities that satisfies that Intent structure.

Now what do I do to pick or choose image and use in my app.

Intent i = new intent(Intent.ACTION_GET_CONTENT).setType("image/*");

// use PackageManager to see if there is anything that supports this
// Intent structure, or just blindly make the following call and handle
// the ActivityNotFoundException

startActivityForResult(i, PICK_IMAGE_REQUEST);

I am using this code , so that only gallery opens and not any other option to pick image

There is nothing in your code that limits it to just a "gallery".

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

Not allowed to comment because I don't have enough points. But here's just a suggestion, how about if you just passed the intent directly? Like this:

startActivityForResult(i, PICK_IMAGE_REQUEST);
Emmagency
  • 7
  • 4
0

Use this line of code rather than what you have done

Intent i = new intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, PICK_IMAGE_REQUEST);
Ravi Rathore
  • 101
  • 1
  • 11