关于同一主题有很多问题,但没有一个为我提供答案。我已经尝试了很多解决方案,但到目前为止没有一个对我有用。
我在片段中调用相机意图并将uri插入到我希望存储图片的新创建的文件中,然后在activityresult上我将uri传递给一个我想在imageview中显示它的新活动和然后继续上传。
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File mImageFile = new File(Environment.getExternalStorageDirectory().getPath()+"/DCIM/" + "Camera/" + File.separator+System.currentTimeMillis()+".jpg");
imageUri = Uri.fromFile(mImageFile);
Log.d("camera", "imageUri: " + imageUri.toString());
intent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri);
startActivityForResult(intent, CAMERACODE);
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode){
case CAMERACODE:{
if (resultCode == Activity.RESULT_OK) {
Intent intent = new Intent(getActivity(), SubmitActivity.class);
intent.putExtra("imageuri", imageUri.toString());
getActivity().startActivity(intent);
在提交活动中:
Bundle extras = getIntent().getExtras();
imageUri = extras.getString("imageuri"); <-- imageUri has the correct path, and the actual file is created and the photo is there. The photo is not showing up on gallery for some reason though, only when browsing the folders. What is the reason for this?
iv = (ImageView) findViewById(R.id.selectedpicture);
iv.setImageURI(Uri.parse(imageUri)); <-- this line causes a NullPointerException.
谁能解释 setImageURI 失败的原因?有什么替代方法吗?我正在使用三星 Galaxy S3