I also had a problem with the lack of access to ExternalStorage for text files from my specified path which was like this:
我还遇到了一个问题,即无法从我指定的路径访问ExternalStorage中的文本文件,如下所示:
/storage/emulated/0/ dictfiles/
Until SKD<=12, I was setting my path as :
在SKD<=12之前,我将我的路径设置为:
private final static String PATH = "/dictfiles/";
String stringPathDirectory = Environment.getExternalStorageDirectory().getAbsolutePath() + PATH;
up to version sdk=12 everything worked without a problem and with sdk=13 it stopped working – permission denied.
在SDK=12版本之前,一切工作都没有问题,而SDK=13则停止工作-权限被拒绝。
MY TEMPORARY SOLUTION
我的临时解决方案
According to the new approach with SDK=13, we can do access to:
根据SDK=13的新方法,我们可以访问:
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
So I entered into the manifest file what the new approach requires and I still couldn't read from my specified path.
Looking at the above permission, we get access to few directories among others PICTURES.
因此,我在清单文件中输入了新方法所需的内容,但仍然无法从我指定的路径中读取。查看上面的权限,我们可以访问其他图片中的几个目录。
So put my directory with text files into the PICTURES directory.
所以把我的目录与文本文件到PICTURES目录。
I changed the access path to my directory and files to:
我将我的目录和文件的访问路径更改为:
String stringPathDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+ PATH;
So now my directory path looks like /storage/emulated/0/Pictures/dictfiles
因此,现在我的目录路径看起来像/存储/仿真/0/Pictures/Dirst Files
But my snippet code:
但我的代码片段如下:
File[] files = directory.listFiles();
which scanned the directory for files, still couldn't find my text files. I think that because Android by default requires graphic files in the Pictures directory and it did, it found .jpg .png .gif but my dicfiles directory with text files was missing. So in all my text files I added .jgp extension to my text files and now the code doesn't skip them.
它扫描了目录中的文件,仍然找不到我的文本文件。我认为因为Android在默认情况下需要图片目录中的图形文件,所以它找到了.jpg.png.gif,但我的包含文本文件的dicfiles目录丢失了。因此,在我的所有文本文件中,我为文本文件添加了.jgp扩展名,现在代码不会跳过它们。
Until I find another solution, this is how I solve it, but I haven't found another solution on the Internet and I've been looking for a long time.
在我找到另一个解决方案之前,这就是我解决它的方法,但我在互联网上没有找到另一个解决方案,我已经寻找了很长时间。
更多回答
我是一名优秀的程序员,十分优秀!