Failed to unmount /mnt/secure/staging - android

android Unable to access files in SD card ####Android无法访问SD卡中的文件
I am working on application where it create text files in the SD card.
I have a receiver which will execute logic to create files in SD card from that point I will keep on store some data into that .
So far it is working properly , but suddenly I stopped working.
I checked logcat output , I found some logs related to SD card mounting.
But do not have an idea to how to resolve this issue.
below are the log statements:
1.464 W/Vold ( 2357): Failed to unmount /mnt/secure/staging (Device or resource busy, retries 3, action 0)
08-23 07:26:31.783 E/ProcessKiller( 2357): Process logcat (3344) has open file /mnt/secure/staging/abc1.txt
08-23 07:26:31.783 E/ProcessKiller( 2357): Process logcat (3345) has open file /mnt/secure/staging/abc2.txt
08-23 07:26:32.845 W/Vold ( 2357): Failed to unmount /mnt/secure/staging (Device or resource busy, retries 2, action 1)
08-23 07:26:33.173 E/ProcessKiller( 2357): Process logcat (3344) has open file /mnt/secure/staging/abc1.txt
I have added permission android.permission.WRITE_EXTERNAL_STORAGE

I think it's just because you're use multiple thread to access file. So, try to use synchronized in your open file function.
synchronized void openFile(String filePath) {
// Code to open file
}

before writing the text file into SD-card you must always check the media state
if(Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED))
{
// read or write file logic here //
}

Related

Android adb push permission denied

I am trying to edit the handheld_core_hardware.xml in `system/etc/permissions
when i push the file after editing it gives that error
adb: error: failed to copy 'handheld_core_hardware.xml' to '/system/etc/permissions/handheld_core_hardware.xml': remote Permission denied
handheld_core_hardware.xml: 0 files pushed. 0.8 MB/s (4027 bytes in 0.005s)
even that i have changed the file to read-write not read-only
Is your device rooted ? I think in order to manipulate those files you have root permissions.

android writing to shared preference getting java.io.IOException: write failed: ENOSPC (No space left on device)

I am downloading files from Internet but I am getting such error. on committing shared preference data
W/SharedPreferencesImpl: writeToFile: Got exception:
java.io.IOException: write failed: ENOSPC (No space left on device)
at libcore.io.IoBridge.write(IoBridge.java:501)
at java.io.FileOutputStream.write(FileOutputStream.java:316)
at com.android.internal.util.FastXmlSerializer.flushBytes(FastXmlSerializer.java:233)
at com.android.internal.util.FastXmlSerializer.flush(FastXmlSerializer.java:254)
at com.android.internal.util.FastXmlSerializer.endDocument(FastXmlSerializer.java:199)
at com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:193)
at android.app.SharedPreferencesImpl.writeToFile(SharedPreferencesImpl.java:600)
at android.app.SharedPreferencesImpl.-wrap2(SharedPreferencesImpl.java)
at android.app.SharedPreferencesImpl$2.run(SharedPreferencesImpl.java:515)
at android.app.SharedPreferencesImpl.enqueueDiskWrite(SharedPreferencesImpl.java:536)
at android.app.SharedPreferencesImpl.-wrap0(SharedPreferencesImpl.java)
at android.app.SharedPreferencesImpl$EditorImpl.commit(SharedPreferencesImpl.java:458)
can anybody help me to solve this problem?
java.io.IOException: No space left on device means there is not enough memory left in internal storage your device. As I can see you have enough memory in your storage. Uninstall the app and install it again.If it is not working, try to install you app in SD card.
Add android:installLocation="preferExternal" in your manifest file.
I think installing the app in SD Card may solve your problem.

Cannot write to sdcard on android emulator: permission denied; storage state: mounted

I am trying to use Debug.startMethodTracing("tracefile"). But I got the error that "E/art: Unable to open trace file '/sdcard/localExp.trace': Permission denied".
The following are what I have tried:
I did add "WRITE_EXTERNAL_STORAGE" to AndroidManifest.xml
2.I used "Environment.getExternalStorageState()". The returned state is "mounted".
3.The application works on real device but got the error on emulator.
I searched a lot about this problem but still can't solve it.

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

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.

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.

Categories

Resources