这是我从图库中获取图像的代码
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 设备上测试此代码时,它不起作用,可能是什么问题?