内部存储路径

时间:2019-05-02 14:34:29

标签: java android

我有此代码来存储图片:

 imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),"fname_" + ".jpg"));
                intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri);
                startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

它将图片存储在 /file:/storage/emulated/0/fname_.jpg

然后我想在imageView中显示图片

  Log.d("URI",imageUri.toString());
        File imgFile = new  File(imageUri.toString());

        Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());



        imageView.setImageBitmap(myBitmap);

但是它说:

E / BitmapFactory:无法解码流:java.io.FileNotFoundException:/file:/storage/emulated/0/fname_.jpg(无此类文件或目录)

我可以在Interer Speicher / fname_.jpg中看到图片

soebody可以告诉我真实的路线吗?

1 个答案:

答案 0 :(得分:0)

我怀疑imageUri.toString()没有返回SD卡中文件的路径, 您可以尝试像这样更改代码:

File imageFile = new 
File(Environment.getExternalStorageDirectory(),"fname_" 
+ ".jpg");
mSavedPath = imageFile.getAbsolutePath();
imageUri = Uri.fromFile(imageFile);
          intent.putExtra(
android.provider.MediaStore.EXTRA_OUTPUT, imageUri);
            startActivityForResult(intent, 
CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

然后再说:

File imgFile = new  File(mSavedPath);
....