简体   繁体   English

向外部存储写入问题

[英]Issue Writing to external storage

I'm working from this tutorial of how to add camera functionality in my app and save the photos taken. 我正在本教程中研究如何在应用程序中添加相机功能并保存拍摄的照片。

https://developer.android.com/training/camera/photobasics.html https://developer.android.com/training/camera/photobasics.html

With this version I can not find the photo's after when saving using 使用此版本时,使用保存后找不到照片

getExternalFilesDir(Environment.DIRECTORY_PICTURES);

The camera works but the pictures are nowhere to be found after. 相机可以工作,但找不到图片。

I have tried to use 我尝试使用

getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)

However with this the camera does not even load. 但是,相机甚至无法加载。

Any advice on why this may be happening would be much appreciated. 对于为什么会发生这种情况的任何建议将不胜感激。

You and Camera both can not use the Environment.DIRECTORY_DCIM at the same time. 您和相机都不能同时使用Environment.DIRECTORY_DCIM。 So when you are trying to access the same and then try to use camera as well, then at that time Camera also tries to access Environment.DIRECTORY_DCIM which is already acquired by you. 因此,当您尝试访问同一文件夹,然后又尝试使用照相机时,那时照相机还会尝试访问您已经获取的Environment.DIRECTORY_DCIM。 Hence Camera does not work for that time. 因此,Camera暂时无法使用。

To implement the Camera in your app: 要在您的应用中实现相机,请执行以下操作:

Intent e = new Intent("android.media.action.IMAGE_CAPTURE");
String state = Environment.getExternalStorageState();
Uri mImageCaptureUri = your required file path's URI;
e.putExtra("output", mImageCaptureUri);
e.putExtra("return-data", true);
startActivityForResult(e, 1);

Now use onActivityResult method to access the captured image. 现在,使用onActivityResult方法访问捕获的图像。

You can use the below direction to save your files in the internal storage 您可以按照以下说明将文件保存在内部存储中

 String PicDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();

then you will find your save files in the below path /storage/emulated/0/Android/data/ your package name /files/Pictures/ 那么您将在以下路径/ storage / emulated / 0 / Android / data / 包名称 / files / Pictures /中找到保存的文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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