我的模拟器SD卡中有一些图像,我想在其上选择一个特定的图像。请参阅下面的代码,
int RESULT_LOAD_IMAGE = 1;
Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
实际上在我的模拟器SD卡中推送一个png图像,但使用上面的代码我的模拟器显示没有找到媒体。指导我,
答案 0 :(得分:2)
使用外部应用程序帮助(如图库)选择图像?
public void pick(View V) {
Intent it = new Intent();
it.setType("image/*");
it.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(it, 101);
}
我在这里使用onActivityResult稍后在imageView上输出它 你可以将它转换为URI,Bitmap或任何你需要的东西
答案 1 :(得分:0)
试试这个,
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case 1:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
InputStream imageStream = getContentResolver().openInputStream(selectedImage);
Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream);
}
}
}