Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7821011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:30:42+00:00 2026-06-02T07:30:42+00:00

Following is my code: if(v.getId() == R.id.button2) { Intent wpIntent = new Intent(); wpIntent.setType(image/*);

  • 0

Following is my code:

    if(v.getId() == R.id.button2)
    {
        Intent wpIntent = new Intent();
        wpIntent.setType("image/*");
        wpIntent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(wpIntent, "Select Picture"), SELECT_PICTURE);
    }
}

public void onActivityResult(int resultCode, int requestCode, Intent data)
{
    if(resultCode == RESULT_OK)
    {
        if(requestCode == SELECT_PICTURE)
        {
            Uri selectedImage = data.getData();
            selectedImagePath = getPath(selectedImage);
            Toast.makeText(this, ""+selectedImagePath, Toast.LENGTH_SHORT).show();
        }
    }
}

private String getPath(Uri selectedImage)
{
    String[] proj = {MediaStore.Images.Media.DATA};
    cursor = managedQuery(selectedImage, proj, null, null, null);
    int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(columnIndex);
}

What’s wrong with this picture? The Toast in onActivityResult doesn’t get shown which means that this thing ain’t working.

What am I doing wrong here?

EDIT: I added some more check and turns out the if(resultCode == RESULT_OK) is not returning true. Why is that so?

EDIT 2 This is weird. Removing both the ‘if’ statements makes the program work just fine. The proper image Uri is generated and the whole thing works just fine. I still don’t understand why the ‘if’ statements return false though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:30:44+00:00Added an answer on June 2, 2026 at 7:30 am

    By default, gallery does not return result code if you not specify in the intent to return result code. You can specify in the intent to return result code by adding this snippet in your code like this:

    Intent wpIntent = new Intent();
    wpIntent.setType("image/*");
    wpIntent.setAction(Intent.ACTION_GET_CONTENT);
    wpIntent.putExtra("return-data", true); //added snippet
    startActivityForResult(Intent.createChooser(wpIntent, "Select Picture"),SELECT_PICTURE);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

consider the following code: const QString& MyClass::getID(int index) const { if (i < myArraySize
Following code is to save image took from camera into photo album. if ([mediaType
The following code causes a NullReferenceException tStartParameter = String.Format(tStartParameter, tTo, tSubject) tProcess = Process.Start(New
I've got the following code that creates a PopupWindow containing an EditText: lbs.setOnTouchListener(new OnTouchListener(){
I'm trying to use the following code to show one intent if the record
Following code iterates through many data-rows, calcs some score per row and then sorts
following code doesn't work with input: 2 7 add Elly 0888424242 add Elly 0883666666
Following code is from a sample of playframework-2.0: /** * Display the dashboard. */
The following code works fine: person = {:a=>:A, :b=>:B, :c=>:C} berson = {:a=>:A1, :b=>:B1,
The following code continues to be displayed even if there are entries in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.