Writing from SD card to SD card does not work, but not permanently

I have a rather tricky problem with Android 2.3: I have an app that collects various logs for debugging and support ( my company makes Linux for rugged hardware), and recently stopped working because it can't write to SD card. Here are the symptoms I saw and the research I did:

  • Happens on multiple devices with multiple types with different SD cards, all of which have been checked for file system corruption (no issues found).
  • All devices report: Environment.getExternalStorageState () equals Environment.MEDIA_MOUNTED.
  • All devices also report Environment.getExternalStorageDirectory (). getAbsolutePath (). canWrite () is false.
  • Through PackageManager.checkPermission (), my app reports that it has WRITE_EXTERNAL_STORAGE permission.
  • OI File Manager can create directories and move files on SD card; my application cannot do this.

This code is enough to cause the crash:

String sdcardDirectory = Environment.getExternalStorageDirectory().getAbsolutePath();
File directory = new File(sdcardDirectory + "/logger");  
    //fails here.  
    Log.w("Logger", "Could not create logger directory.");  


Since I have access to the keys for this device, I even went so far as to sign the application with the platform key and run it as android.uid.system, with no luck. Does anyone have any idea?


source to share

1 answer

It turns out that this is a case, partly a bad diagnosis on my part, and partly a clear change in 2.1 - 2.3.

The bad diagnosis was that the created directory was actually being created. The obvious change between 2.1 and 2.3 could be Android internally, or maybe we tweak paths, PATH and symlinks in our own builds. Next, starting with the code in the original post, there are multiple exec () calls to get eg. output from logcat and copies of various bits of useful information in / proc; using absolute paths to the commands that fix the problem.

Thanks for helping us make decisions.



All Articles