gpt4 book ai didi

Unable to grant permission to my android app to read a text file on android 13(无法授予我的Android应用程序读取Android 13上的文本文件的权限)

转载 作者:bug小助手 更新时间:2023-10-25 15:25:12 25 4
gpt4 key购买 nike



i am implement an android application in java and everything was working perfectly until i install it on an android 13 version . Since then , i can't grant the permission to read file ( specially text file ) . How could i solve it ?

我正在用Java实现一个Android应用程序,一切都运行得很好,直到我把它安装在一个Android 13版本上。从那以后,我不能授予读取文件(特别是文本文件)的权限。我怎么才能解决它呢?


更多回答
优秀答案推荐

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.

在我找到另一个解决方案之前,这就是我解决它的方法,但我在互联网上没有找到另一个解决方案,我已经寻找了很长时间。


更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com