1
工作,这是我从库抓取图像库的目的不是在Android 4.0.3
intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, GALLERY_INTENT);
代码,这是onActivityResult()
方法
if(requestCode==2 && resultCode == RESULT_OK){
Uri _uri = data.getData();
if (_uri != null) {
//User had pick an image.
Cursor cursor = getContentResolver().query(_uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
cursor.moveToFirst();
//Link to the image
final String imageFilePath = cursor.getString(0);
cursor.close();
Intent intent = new Intent(HomeActivity.this,ConfirmPicture.class);
intent.putExtra(INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED, true);
intent.putExtra("IMAGE_PATH", imageFilePath);
intent.putExtra("OUTLET_ID", 0);
intent.putExtra("OUTLET_NAME", "name");
startActivity(intent);
}
该代码是工作的罚款上的Android 2.3 .4版本,但当我在4.0.3设备上测试此代码时,它不起作用,可能是什么问题?
当你说: “它不工作” 究竟是什么意思?你能更具体地说明它做了什么,不做什么?即抛出异常了吗?或者它只是不开放画廊?当您试图发射意图时,Logcat中是否有任何消息? – FoamyGuy 2013-02-12 14:23:17
该方法中的imageFilePath通过画廊意图为我提供了正确的图像路径,但它并未显示在ImageView中。在4.0.3版本中。 – 2013-02-13 05:15:52
你有没有答案,如果是的话请分享我也有同样的问题 – 2013-03-23 06:35:34