Android 无法加载图片

Android 无法加载图片,android,android-sharedpreferences,Android,Android Sharedpreferences,我在尝试加载手机上保存的图片时遇到问题 我有一个“助手类” 下面是我试图上传照片的地方: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_profile2); iv = (ImageView) findViewById

我在尝试加载手机上保存的图片时遇到问题

我有一个“助手类”

下面是我试图上传照片的地方:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile2);

        iv = (ImageView) findViewById(R.id.ivPic);
        btnTakePic = (Button) findViewById(R.id.btnpic);
        btnPickPicture = (Button) findViewById(R.id.btnpicpic);


        try {
            bitmap = BitmapFactory.decodeStream(this.openFileInput(PIC_FILE_NAME));
        } catch (FileNotFoundException e) {

            bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.cam);
        }
        iv.setImageBitmap(bitmap);
        btnTakePic.setOnClickListener(this);
        btnPickPicture.setOnClickListener(this);
    }

    public void onClick(View v) {
        Intent intent = null;
        if (v == btnTakePic) {
            intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent, TAKE_PICTURE);
        } else if (v == btnPickPicture) {
            Intent pickPickIntent = new Intent(Intent.ACTION_PICK);
            File picDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
            String picDirPath = picDir.getPath();
            Uri uData = Uri.parse(picDirPath);
            pickPickIntent.setDataAndType(uData, "image/*");
            startActivityForResult(pickPickIntent, PICK_PICTURE);

        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == TAKE_PICTURE && resultCode == RESULT_OK)
        {
            bitmap = (Bitmap) data.getExtras().get("data");
            iv.setImageBitmap(bitmap);
            FileHelper.saveBitmapToFile(bitmap,getApplicationContext(),PIC_FILE_NAME);
            Bitmap bitmapx = iv.getDrawingCache();
            Intent intent = new Intent(this, MainActivity.class);
            intent.putExtra("BitmapImage", bitmapx);

        } else if (requestCode == PICK_PICTURE) {
            if (resultCode == RESULT_OK) {
                Uri URI = data.getData();
                String[] FILE = {MediaStore.Images.Media.DATA};
                Cursor cursor = getContentResolver().query(URI,
                        FILE, null, null, null);
                cursor.moveToFirst();
                options = new BitmapFactory.Options();
                int columnIndex = cursor.getColumnIndex(FILE[0]);
                String ImageDecode = cursor.getString(columnIndex);
                cursor.close();
                options.inSampleSize = 5;
                Bitmap bmp = BitmapFactory.decodeFile(ImageDecode, options);
                iv.setImageBitmap(bmp);

                FileHelper.saveBitmapToFile(bmp,getApplicationContext(),PIC_FILE_NAME);

                Bitmap bitmapx = iv.getDrawingCache();
                Intent intent = new Intent(this, MainActivity.class);
                intent.putExtra("BitmapImage", bitmapx);
            }
        }
    }
这里是我尝试加载保存的图片的地方:

    private void updateHeader()
    {

        ImageView ivHeader = (ImageView) mNavigationView.getHeaderView(0).findViewById(R.id.ivHeader);

        try{
            bitmap= BitmapFactory.decodeStream(this.openFileInput(PIC_FILE_NAME));
            ivHeader.setImageBitmap(bitmap);
        }
        catch (FileNotFoundException e){
            Toast.makeText(getApplicationContext(),"error occured",Toast.LENGTH_LONG);
        }

    }

我必须说,Toast消息没有显示,也没有错误。应用程序没有崩溃,但图片保持不变

确保您具有外部读取存储权限。这是


另外,请确保您已将该权限添加到AndroidManifest.xml

我具有外部读取存储权限。事实上,我也有相机和实习生的许可。你必须拍照和拍照,但你没有告诉谁你有这个问题。两者都不起作用。。嗯,它们确实有效,但我根本无法加载图片
    private void updateHeader()
    {

        ImageView ivHeader = (ImageView) mNavigationView.getHeaderView(0).findViewById(R.id.ivHeader);

        try{
            bitmap= BitmapFactory.decodeStream(this.openFileInput(PIC_FILE_NAME));
            ivHeader.setImageBitmap(bitmap);
        }
        catch (FileNotFoundException e){
            Toast.makeText(getApplicationContext(),"error occured",Toast.LENGTH_LONG);
        }

    }