L.Butz
L.Butz

Reputation: 2616

Load an Image from the Gallery in Android

I'm currently doing a Widget in Android. It is on the market and it's free. I want to surprise the users by let them choose a picture they want to show in the widget.

Now...

If the widget is clicked, a PreferenceActivity appears. <-- Works!

In this Activity the user should be able to choose a picture from the phone picture gallery. <-- HOWTO?

After the User selected the prefered picture, the picture path or the drawable object should be stored in the SharedPreferences. <-- Would be really nice!

Is there any solution?

Thx!

Upvotes: 2

Views: 7788

Answers (1)

dlongest
dlongest

Reputation: 462

In order to get an image from the Gallery, you must send an intent to start up the Gallery for the user to choose an image as such

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);  
intent.setType("image/*");
startActivityForResult(intent, 10);

This will start the gallery and will call onActivityResult within your activity.

Upvotes: 12

Related Questions