Question

I'm getting a very strange situation while developing an AIR application for android: - I am getting error #3001 - "File or directory access denied" when I am trying to copy files to the sdcard. I have added the following permission to the manifest but it did not fix the issue:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

I have tried to unplug the usb cord prior to launching the app in order to avoid any collisions but it doesnt help. The sdcard "lock" button remains in "unlocked" state. I have also tried to use another sdcard but the result is the same.

The version of android is 4.0.4 and the air sdk is 3.2

Any advice will be highly appreciated.

UPDATE 4/8/2014

My apologies, in fact the copy operation throws error 3002 - file or directory exists and the error 3001 is frown by destinationDir.createDirectory() which goes before it. However it becomes more incomprehensible since sd card is empty and I dont see anything on it. As I see from debugger the "exists" property of destination is false so I really dont understand why it throws error 3002.

Here is the source which provokes the exception:

var sourceDir:File = File.applicationDirectory.resolvePath(Model.INTERNAL_ASSETS_FOLDER);               
var destination:File = Model.externalAssetsDirectory;

try {
        if (!destination.exists) {
            destination.createDirectory();
        }

        sourceDir.copyTo(destination, true);

} catch (e:Error) {
        trace(e.message)
}
Was it helpful?

Solution

It seems that the stock version of android doesn't allow non-system apps write anything to the sdcard. Here is a very good article which describes this issue:

http://www.chainfire.eu/articles/113/Is_Google_blocking_apps_writing_to_SD_cards_/

However there are few methods to overcome this limitation but they require some low level manipulations or a installing a custom version of android.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top