2

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!

Winona
  • 2,950
  • 2
  • 21
  • 29

1 Answers1

1

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.

JoxTraex
  • 13,423
  • 6
  • 32
  • 45
  • 1
    Thanks for your response! However, I found out another problem while using Intent.ACTION_PICK. If I use that, I cannot display the image after it has been clicked., it will return me to my app straightaway. & Oops, and I wasn't able to find the Manifest for the Gallery Application on https://github.com/android – Winona Feb 02 '12 at 04:42
  • Seems they remove it, let me get it for you – JoxTraex Feb 02 '12 at 04:45
  • Thanks for helping! But may I ask, where do I put the above code into the manifest file? Within my activity? Or within the app? – Winona Feb 02 '12 at 04:53
  • It doesn't belong in your manifest, you need to pass your intent to match that. – JoxTraex Feb 02 '12 at 04:54
  • Sorry, I'm a little confused. May I know how to go about doing that? – Winona Feb 02 '12 at 04:58
  • I have edited my question with modifications as of what you have told me, can you please take a look and see if you could help me further? Thanks! – Winona Feb 02 '12 at 05:05