getExternalFilesDir(null) gives java.io.IOException: Read-only file system - android

I'm trying to write a text file in the root folder of my app with the below code
File file = new File(getExternalFilesDir(null), "values.txt");
file.createNewFile();
All i am getting is java.io.IOException: Read-only file system
i have uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" in the manifest file.
How can i fix this issue ?
I have tried it on an emulator and a nexus 7 and cant seem to find what is causing the issue.
I see a lot of answers talking about remounting my file system but i can expect everyone that downloads the app to do that.

getExternalFilesDir(null)
Will return, The path of the directory holding application files on external storage. Returns null if external storage is not currently mounted so it could not ensure the path exists; you will need to call this method again when it is available.
So In your case we don't know whether external storage is mounted or not, but as you want to put file on root folder of your app. just use getFilesDir(). It will store your file in internal storage where your application files are stored.

Related

Issue with application files folder in android

I'm trying to create zip file inside my application files folder (/data/data/myapp/files) but getting "failed to create zip file | open failed: EACCES (Permission denied)" error message every time. As I can see using android debug bridge, my files folder have "rwx------" permissions and "root" owner and group. I think this is the problem but I can't understand why my folder have this owner and group?
Make sure you :
have rooted your device
have the rights to write on the internal storage
are not trying to test it with the usb storage enabled on your phone
added the permission <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" /> in your manifest
I solved the problem by manually setting right owner, group and permissions on my application files folder (using chmod, chown and chgrp commands). It does not seem like an answer, because it is still unclear why this folder got wrong permissions but unfortunately I don't have enough time to understand where problem is.

sdcard permission denied android

I am trying to do method profiling for my application on Android 2.1 htc eris. It complains:
06-15 15:48:04.602: E/dalvikvm(826): Unable to open trace file '/sdcard/com.mayapp.trace': Permission denied
I have the following entry for user permission on my AndroidManifest.xml:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
When I do adb push, I get the following error:
adb push AndroidManifest.xml a.txt
failed to copy 'AndroidManifest.xml' to 'a.txt': Read-only file system
Am I missing something here?
This may not be the answer but you could use
File dir = Environment.getExternalStorageDirectory();
to access external sd card. My assumption is you wrote the directory yourself.
It was a combination of badly placed sd card and read/write access to the sdcard. Used adb push/pull to verify the sd card and also used adb remount to change the access. that solved the issue.

how to grant android mediaserver file write permission?

I am developing several AudioEffect subclasses that are being compiled into Android 4.0.3 ICS... I am trying to dump raw PCM data to files, but because the AudioEffects run in the context of the mediaserver process it seems there is no file writing permissions available.
fopen("/data/local/tmp/pcm_in.pcm", "w");
is returning a NULL pointer and errno 13 (permission denied).
Any ideas how I can grant mediaserver this permission, or write to a folder I can access? I'm compiling the OS, so anything goes...
More specifically: How are permissions for these native/system services determined? I don't suppose they have a AndroidManifest.xml...
I suspect the problem is that you don't have permissions to create a file at /data/local/tmp. In fact i'm not even sure that directory exists on Android.
Instead you should either use the private storage for an app or save the files to the SD card. See this for more information: http://developer.android.com/guide/topics/data/data-storage.html
Maybe you can just create a folder with permission.
root#android:/mount -o remount,rw /
root#android:/mkdir test
root#android:/chown media:media test
root#android:/chmod 777 test
Then you can do whatever you want.
z.B.
fopen("/test/pcm_in.pcm", "w");

Accessing the /cache directory in the Android filesystem

How can I write a file in the /cache directory? I continue to get a FileNotFoundException (Permission denied).
Someone told me about the android.permission.ACCESS_CACHE_FILESYSTEM but i can't find it in the Android reference.
Any help will be appreciated.
EDIT: i'm using level 13 apis
You can only write to the cache directory of your own application: use context.getCacheDir() to get its location.

java.io.FileNotFoundException: /sdcard/DCIM/ROBIN.jpg (No such file or directory)

I'm getting an error on the following line of code:
FileInputStream is = new FileInputStream("/sdcard/DCIM/ROBIN.jpg");
The error is:
java.io.FileNotFoundException: /sdcard/DCIM/ROBIN.jpg (No such file or directory)
But the image is present in the directory
My USB connection is Charge only
Never hardcode paths like /sdcard. For example, /sdcard is wrong on most Android devices. Use Environment.getExternalStorageDirectory() to find the root of external storage.
Make sure you have set the permission WRITE_EXTERNAL_STORAGE in your manifest.

Categories

Resources