0

first manner:

    Intent intent = new Intent();
    intent.setType( "image/*" );
    intent.setAction( Intent.ACTION_GET_CONTENT );
    startActivityForResult( Intent.createChooser( intent , "select picture" ) , REQUEST_LOAD_IMAGE );

second manner:

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

After entering the select picture Activity, the lists are different. Could you tell me the reason?

If I want to list all the photos on my android phone, How should I do? Thanks

Zachary
  • 127
  • 1
  • 2
  • 15
  • 1
    The first says "I want a picture". The second says "I want something out of this specific collection of content". Not all pictures are available through `MediaStore`, particularly those managed by other apps and cloud storage services (e.g., Dropbox). – CommonsWare Oct 20 '15 at 13:23

2 Answers2

0

If you want the user to choose something based on MIME type, use ACTION_GET_CONTENT.

If you have some specific collection (identified by a Uri) that you want the user to pick from, use ACTION_PICK.

In case of a tie, go with ACTION_GET_CONTENT. While ACTION_PICK is not formally deprecated, Dianne Hackborn recommends ACTION_GET_CONTENT.

Taken from CommonsWare's answer here

Community
  • 1
  • 1
Bhargav
  • 8,118
  • 6
  • 40
  • 63
0

To list all the photos, you could do something like this:

Suppose you have a button and you open image picker onClick,

int SELECT_FILE = 1;
button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                intent.setType("image/*");
                startActivityForResult(
                        Intent.createChooser(intent, "Select File"),
                        SELECT_FILE);
            }
        });

And suppose you have an imageView, in which you display the selected image, then:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            Uri selectedImageUri = data.getData();
            String[] projection = {MediaStore.MediaColumns.DATA};
            Cursor cursor = managedQuery(selectedImageUri, projection, null, null,
                    null);
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
            cursor.moveToFirst();

            String selectedImagePath = cursor.getString(column_index);
            Picasso.with(this)
                    .load(selectedImagePath)
                    .into(imageView);
        }
    }
Amit Tiwari
  • 3,684
  • 6
  • 33
  • 75