所以我正在拍照,然后我尝试将其保存到该路径中,但我无法访问它。尝试过这个<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 block 时,程序在第一行跳出 try。
我希望这是有道理的。英语不是我的主要语言。任何帮助将不胜感激。
最佳答案
如果没有 logcat,调试将会很困难,但你可以尝试一下这个作为初学者
android.permission.READ_EXTERNAL_STORAGE
您有写入权限,但无权读取。有关更多详细信息,请参阅此 Android Permissions
关于java - FileNotFoundException :/storage/emulated/0/Pictures/pic. jpg:打开失败:EACCES(权限被拒绝),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26208751/