Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving only images from gallery when firing android image chooser intent

I am allowing the user to select an image from the device using the following code:

(from this post)

public class BrowsePicture extends Activity {

private static final int SELECT_PICTURE = 1;

private String selectedImagePath;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ((Button) findViewById(R.id.Button01))
            .setOnClickListener(new OnClickListener() {

                public void onClick(View arg0) {

                    // in onCreate or any event where your want the user to
                    // select a file
                    Intent intent = new Intent();
                    intent.setType("image/*");
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                    startActivityForResult(Intent.createChooser(intent,
                            "Select Picture"), SELECT_PICTURE);
                }
            });
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_PICTURE) {
            Uri selectedImageUri = data.getData();
            selectedImagePath = getPath(selectedImageUri);
        }
    }
}

public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    int column_index = cursor
            .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

The code works fine, but it also displays application resources within the selected area. Is there any way I can remove application resources from the selection area?

like image 959
2bard Avatar asked Feb 14 '11 11:02

2bard


People also ask

How do I get a list of images in a specific folder on Android?

You can use below code to get all images from specific folder. 1) First you need to define File object to get the storage and appened the name of the folder you want to read. File folder = new File(Environment. getExternalStorageDirectory().


1 Answers

No. That is up to the application the user chooses to satisfy the SELECT_PICTURE.

That said, there are ways to block images from showing in the Gallery all the time by adding flag files to folders or hiding the folders, but that is not what you asked. You can't do it from your program.

like image 75
Unconn Avatar answered Nov 09 '22 12:11

Unconn