【问题标题】:FileNotFoundException: /storage/emulated/0/Pictures/pic.jpg: open failed: EACCES (Permission denied)FileNotFoundException:/storage/emulated/0/Pictures/pic.jpg:打开失败:EACCES(权限被拒绝)
【发布时间】:2014-10-06 00:49:40
【问题描述】:

所以我正在拍照,然后我试图将其保存到该路径中,但我无法访问它。试过这个<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> 并没有用。

这就是我拍照并保存的方式。

private void takePic(View v) 
    {
        // se usa para usar algun app del phone para usar sus cosas para hacer lo que queremos envez de crearlo from scratch
        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");

        //guarda la imagen
        File imgFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"pic.jpg");

        imgUri = Uri.fromFile(imgFile);

        intent.putExtra(MediaStore.EXTRA_OUTPUT, imgUri);

        //le dice que use el app de camare y le dice que use la camara de atras 1 = la de atras
        startActivityForResult(intent, TAKE_PICTURE);
    }

    //hay que hacerle override para que haga algo que no es parte del metedo.
    //Por ejemplo quiero que guarde la imagen donde yo quiera y no donde tiene por default.
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent)
    {
        super.onActivityResult(requestCode, resultCode, intent);

        //si presiono el buton de ok
        if(resultCode == Activity.RESULT_OK)
        {
            Uri selectedImg = imgUri;

            // te deja saber que termino de usar la imagen
            getContentResolver().notifyChange(selectedImg, null);

            ImageView imgV = (ImageView)findViewById(R.id.SteerinRackImgVw);

            // lo mismo de horita
            ContentResolver cR = getContentResolver();

            //tiene la data de la img
            Bitmap btMp;

            try 
            {
                btMp = MediaStore.Images.Media.getBitmap(cR, selectedImg);

                imgV.setImageBitmap(btMp);

                //display a small popup de lo que esta pasando
                Toast.makeText(TestMain.this,selectedImg.toString(), Toast.LENGTH_LONG).show();
            } 

            catch (Exception e) 
            {
                Log.e("error", e.toString());
            }
        }
    }

希望我没有错过任何括号:P

当我调试 try 和 catch 块时,程序在第一行中断了 try。

我希望这是有道理的。英语不是我的主要语言。任何帮助将不胜感激。

【问题讨论】:

  • 所以没有人知道如何解决它?太棒了……
  • 请发布您的日志猫并尝试添加读取外部存储的权限
  • 好的,会的。当我拿回我的电脑时,我会试试这个

标签: java android


【解决方案1】:

没有 logcat 会很难调试,但是初学者可以试试这个

android.permission.READ_EXTERNAL_STORAGE

您有写入权限,但没有读取权限。更多详情请参见Android Permissions

【讨论】:

  • 错了!任何声明 WRITE_EXTERNAL_STORAGE 权限的应用都会被隐式授予 READ_EXTERNAL_STORAGE 权限。
  • 如果您看到原始问题,则仅使用了 android.permission.WRITE_EXTERNAL_STORAGE。这就是为什么我也添加了 READ 权限。对
猜你喜欢
  • 1970-01-01
  • 2016-10-15
  • 2021-05-15
  • 1970-01-01
  • 1970-01-01
  • 2015-06-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多