Winona
Winona

Reputation: 2970

Android - Launch Gallery Folder and Select Image

I am doing an app which requires the use of the gallery viewer. I am using a button to launch the gallery activity.

By using this code:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/external/images/media"))); 

It returns me all the images in the gallery from different photo albums, where I would only want to display the default camera album (is this possible?), and when I click on the image to view it, it is fine until I click on the back button, the back button goes straight back to my app and does not stay in the gallery. I would like the back button to go back to the gallery (so that the user can view other images too), is that possible?

Any help would be appreciated and thank you for your time and contribution :)

So far, this is what I have gotten

Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
intent.setDataAndType(Uri.parse("content://media/external/images/media"), "image/*");
        startActivityForResult(intent, 0); 

But whenever I load click to load the image, it directs me back to my app straightaway without loading the image. Can someone help me with this? Thanks!

Upvotes: 2

Views: 6113

Answers (1)

jtt
jtt

Reputation: 13541

Use startActivityForResult() instead of startActivity() since you need the data returned back to you. Along with this you need to use the Intent.ACTION_PICK.

Specifically you need to have your application interact with the gallery to do this. Which would require you returning the image back to your application.

This is easy to determine if you look at the Manifest for the Gallery Application.

You can search for it here: https://github.com/android

Update Gallery Manifest

<intent-filter>
           <action android:name="android.intent.action.PICK" />
           <category android:name="android.intent.category.DEFAULT" />
           <data android:mimeType="image/*" />
           <data android:mimeType="video/*" />
</intent-filter>

Meaning you just need to set the data and the mimetype.

Upvotes: 1

Related Questions