Exception 'open failed: EACCES (Permission denied)' on Android
I had the same problem... The <uses-permission
was in the wrong place. This is right:
<manifest>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
...
<application>
...
<activity>
...
</activity>
</application>
</manifest>
The uses-permission
tag needs to be outside the application
tag.
open failed: EACCES (Permission denied)
I ran into a similar issue a while back.
Your problem could be in two different areas. It's either how you're creating the file to write to, or your method of writing could be flawed in that it is phone dependent.
If you're writing the file to a specific location on the SD card, try using Environment variables. They should always point to a valid location. Here's an example to write to the downloads folder:
java.io.File xmlFile = new java.io.File(Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
+ "/Filename.xml");
If you're writing the file to the application's internal storage. Try this example:
java.io.File xmlFile = new java.io.File((getActivity()
.getApplicationContext().getFileStreamPath("FileName.xml")
.getPath()));
Personally I rely on external libraries to handle the streaming to file. This one hasn't failed me yet.
org.apache.commons.io.FileUtils.copyInputStreamToFile(is, file);
I've lost data one too many times on a failed write command, so I rely on well-known and tested libraries for my IO heavy lifting.
If the files are large, you may also want to look into running the IO in the background, or use callbacks.
If you're already using environment variables, it could be a permissions issue. Check out Justin Fiedler's answer below.
Related Topics
Edittext, Clear Focus on Touch Outside
Connectivitymanager.Connectivity_Action Deprecated
Recyclerview Itemtouchhelper Buttons on Swipe
Support Fragmentpageradapter Holds Reference to Old Fragments
Background Listview Becomes Black When Scrolling
Android Viewpager with Bottom Dots
How to Set Emoji by Unicode in a Textview
Disabling of Edittext in Android
Refreshing Data in Recyclerview and Keeping Its Scroll Position
Linearlayout Not Expanding Inside a Scrollview
How to Create a Http Server in Android
How to Change Status Bar Color to Match App in Lollipop? - Android
Android Canvas: Draw Transparent Circle on Image
How to Programmatically Scroll a Scroll View to a Specific Edit Text
Android Viewpager as Image Slide Gallery