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 6067595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:37:29+00:00 2026-05-23T09:37:29+00:00

I have a Select image in a PreferenceActivity: Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

  • 0

I have a “Select image” in a PreferenceActivity:

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

startActivityForResult(i, IMAGE_SELECT); 

But when I pick an image from Gallery, it does not return anything to my PreferenceActivity‘s onActivityResult:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    Toast.makeText(getApplicationContext(), "THIS TOAST IS NOT SHOWING",
            Toast.LENGTH_LONG).show();

}

What more I need to do? Add something to the manifest? Is it impossible?

This is my “whole” class (omitted irrelevant code):

package com.xuso.myapp;


import yuku.ambilwarna.AmbilWarnaDialog;
import yuku.ambilwarna.AmbilWarnaDialog.OnAmbilWarnaListener;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.provider.MediaStore;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;



public class Settings extends PreferenceActivity {

    protected static final int NEED_RESTART = 2;
    protected static final int IMAGE_SELECT = 3;
    private int bg_color; //There are a lot more

    private Context context = this;
    private int result = RESULT_CANCELED;

    private SharedPreferences sp;
    private SharedPreferences.Editor editor;


    Preference pref_bg_color; //There are a lot more



    public void getPrefs(){

        sp = getSharedPreferences("myapp_prefs", Activity.MODE_PRIVATE);
        editor = sp.edit();

        bg_color = sp.getInt("pref_bg_color", 0xff000000);
        //... and the rest of the GETs.

    }






    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.settings);


        getPrefs();


        //A lot of declarations of listeners when Preferences pressed
        //...
        //...
            pref_bg_image.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {

                    Intent i = new Intent(Intent.ACTION_PICK,
                               android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(i, IMAGE_SELECT); 


                    return false;
                }
            });


        //...
    //...
    //More and more declarations of Preferences.





    }



    //This is for returning results with preferences changes to the Main activity
    private void getBackAndCommit()
    {
        Intent intent= getIntent();
        setResult(result, intent);
        finish();
        overridePendingTransition(0, 0);
    }


    //Commit changes on back pressed
    public void onBackPressed ()
    {

        getBackAndCommit(); 

    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch(requestCode) { 
        case IMAGE_SELECT:
            if(resultCode == RESULT_OK){  
                Uri selectedImage = data.getData();
                String[] filePathColumn = {MediaStore.Images.Media.DATA};

                Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
                cursor.moveToFirst();

                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                String filePath = cursor.getString(columnIndex);
                cursor.close();


                Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
            }
        }

    }



}

And this is my manifest:

<application android:icon="@drawable/myapp_icon" android:label="@string/app_name"
>
    <activity android:name=".Main"
              android:label="@string/app_name"
              android:theme="@android:style/Theme.NoTitleBar"
              >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>


    </activity>

    <activity android:name=".Settings"
              android:label="@string/app_name"
              >
    </activity>

</application>
  • 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-05-23T09:37:30+00:00Added an answer on May 23, 2026 at 9:37 am

    Must work, added whole class:

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    
    public class StackOverflowAppActivity extends Activity {
        private final int PICK_IMAGE = 0;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(i, PICK_IMAGE);
    
    
        }
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
    
            switch (requestCode) {
    
            case PICK_IMAGE:
                if (resultCode == RESULT_OK) {
                    // do your thing
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails 3.2 app where a user clicks an image to select
I have a form with image thumbnails to select with checkboxes for downloading. I
I have the following query: $img_sub_qry = SELECT * FROM images JOIN imagsub ON
I'm trying to do the following: I have a set of images and select
If we have two tables, say; users, and images, how do we select users
I have an app where users select images they wish to print, the print
My database have got 4 table : users id username images id user_id image
I have to select following image button. How can I do that using HtmlUnit?
I've implemented a PickerController to have a user select an image, but I want
//below In my application i have a button select image from sdcard and on

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.