简体   繁体   中英

FileNotFoundException: /storage/emulated/0/Pictures/pic.jpg: open failed: EACCES (Permission denied)

So I'm taking a picture and after that I'm trying to save it into to that path, but I can't access it. Tried this <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> and didn't work.

This is how I'm Taking the picture and saving it.

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());
            }
        }
    }

Hopefully I didn't miss any brackets :P

When I debug the try and catch block, the program breaks out of the try, on the 1st line.

I hope this makes sense. English isn't my main language. Any help would be greatly appreciated.

Without logcat it is going to be hard to debug, but you could try this for starters

android.permission.READ_EXTERNAL_STORAGE

You have permission to write, but not read. See this for more details Android Permissions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM