Android:打开失败的eacces权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24217245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android : open failed eacces permission denied
提问by user3201607
i am new to android. i have tried this code
我是安卓新手。我试过这个代码
in manifest file i wrote this
在清单文件中我写了这个
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
in java code
在java代码中
File sdcard = Environment.getExternalStorageDirectory();
//Get the text file
File file = new File(sdcard,"store.txt");
but i am getting above exception
但我正在超越例外
i want to perform file read and write operations and i am using version 4.4.2.
我想执行文件读写操作,我使用的是 4.4.2 版。
i am getting this error
我收到这个错误
06-14 02:19:44.491: D/Shopping Cart(1700): open failed: EACCES (Permission denied)
采纳答案by Giru Bhai
Is your permission is right place in manifest
file as
您的权限是否在manifest
文件中的正确位置
<application>
...
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
</manifest>
Edit
编辑
Try to edit the Emulator
尝试编辑模拟器
- go to android virtual device manager and then edit the emulator
- set say 100 MB for Sd card for the respected emulator and say Ok
- save and close emulator and start
- path saved in DDMS is mnt/sdcard/yourfilename
- 转到android虚拟设备管理器,然后编辑模拟器
- 为受人尊敬的模拟器设置 100 MB 的 Sd 卡并说 Ok
- 保存并关闭模拟器并启动
- DDMS 中保存的路径是mnt/sdcard/yourfilename
it worked for me the app is not giving Error and is working
它对我有用,应用程序没有给出错误并且正在工作
Please see more at this link Cannot Write to sdcard in Android emulatorand this link Guide to Emulating an SD Card Using the Google Android Emulator
请参阅此链接无法在 Android 模拟器中写入 sdcard和此链接使用 Google Android 模拟器模拟 SD 卡的指南
回答by greenapps
Under kitkat your app can only write to an app specific directory on the -removable- sd card. You get possible directories using getExternalFilesDirs().
在kitkat 下,您的应用程序只能写入-removable- sd 卡上的应用程序特定目录。您可以使用 getExternalFilesDirs() 获取可能的目录。