如何从图库/相机中选择图像?

时间:2014-08-06 18:13:41

标签: android image

我使用此代码:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);

但是它显示了我手机上的所有照片,还有其他的图库/相机文件。我怎么能改变它?

2 个答案:

答案 0 :(得分:1)

使用此代码仅从图库/相机中选择图像

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

这应该适合你。

答案 1 :(得分:1)

试试这个。你需要

import android.provider.MediaStore.Images.Media;

.
.
int IMAGE_PICKER_SELECT = 0;
.
.


Intent i = new Intent(Intent.ACTION_PICK, Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, IMAGE_PICKER_SELECT);


/**
 * After photo is selecte, you can do the processing.
 */
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == IMAGE_PICKER_SELECT  && resultCode == Activity.RESULT_OK) {
       // some code
    }
}