我尝试创建一个获取图像文件的新意图,并根据意图的结果获得图像uri并设置为imageView但这在我的AVD中工作正常,甚至在Bluestacks中但在我的手机中不起作用(已安装)转换为apk后)。出现图像选择屏幕,但在选择图像后,只有空白显示在imageView中。
这是我的代码,点击imgView
imgView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select contact Image"),1);
}
});
my on intent from intent method
public void onActivityResult(int reqCode,int resCode,Intent data)
{
super.onActivityResult(reqCode,resCode,data);
if(resCode==RESULT_OK) if (reqCode == 1) {
imgView.setImageURI(data.getData());
imgUri = data.getData();
}
}
注意:我的图像视图是100 * 100像素的缩放图像视图
答案 0 :(得分:0)
试试这个
//this code calls the app or phone to pick an image from the gallery
pick = 0;
Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, pick);
并在结果活动中使用此
//process image gotten from gallery
if (requestCode == pick && resultCode == getApplicationContext().RESULT_OK) {
Uri imgUri = data.getData();
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imgUri));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ImageView.setImageBitmap(bitmap);
}