Winona
Winona

Reputation: 2970

Image in Gallery not shown

My app has tabs and one of it contains buttons to call the system gallery. I am able to access the gallery and folder, but when I want to display an image by clicking on it, the gallery disappears and returns me to my app.

This is my code:

    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
    photoPickerIntent.setType("image/*");
    startActivityForResult(photoPickerIntent, 1);

May I know how to go about display the image? Thanks all in advance!

This is what I get when I launch gallery using the button and the images are in there but I am unable to launch and view the image on my phone.

gallery enter image description here

Upvotes: 1

Views: 414

Answers (3)

SolArabehety
SolArabehety

Reputation: 8606

Your problem is that the intent need onActivityResult method. It is a little late, but if you need the answer you can do this

final static int REQUEST_IMAGE_CAPTURED = 1;
private Uri uriImage;

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);

        Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

        startActivityForResult(intent, 1);
}

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            if (requestCode == REQUEST_IMAGE_CAPTURED) {
                uriImage = data.getData();
                Toast.makeText(MyClass.this, uriImage.getPath(), Toast.LENGTH_LONG).show();

                // Your code
            }
        } else if (resultCode == RESULT_CANCELED) {
            uriImage = null;
            finish();
        }
    }

Good Luck!

Upvotes: 0

jtt
jtt

Reputation: 13541

Read this documentation to learn how to implement on onActivityResult(xx)

http://developer.android.com/reference/android/app/Activity.html

Upvotes: 0

jeet
jeet

Reputation: 29199

Have you implemented onActvityResult method, on activityResult you need to fetch data from intent, and need to display image from this data, data contain imagepath.

Upvotes: 1

Related Questions