当前位置: 动力学知识库 > 问答 > 编程问答 >

actionscript 3 - Android - can only save files when connected to PC

问题描述:

I am devoloping an app where at certain points the user can save an image file to the sdcard.

All works fine when the phone is connected to the PC but when I disconnect my phone and launch the app, the file saving does not work.

I am guessing that I should use a different path to save when not connected to a PC?

my current path is

 "//mnt/sdcard/DCIM/Camera/image"+Math.random()*10000+".jpg"

I am using pure AS3 AIR to develop.

here's the code:

var bmd:BitmapData = new BitmapData(Main.instance.stage.stageWidth, Main.instance.stage.stageHeight);

bmd.draw(_board)

var je:JPGEncoder = new JPGEncoder(100);

var ba:ByteArray = je.encode(bmd);

var fl:File = File.documentsDirectory.resolvePath("//mnt/sdcard/DCIM/Camera/image"+Math.random()*10000+".jpg");

try{

var fs:FileStream=new FileStream;

fs.open(fl,FileMode.WRITE);

fs.writeBytes(ba,0,ba.length);

fs.close();

}

catch(e:Error){

Main.instance.tf.text = e.message;

}

Thanks in advance,

网友答案:

Android application storage directories are as follows:

Directory in which the app is installed (read-only)

File.applicationDirectory
/data/data/app.appID/app/assets

Private storage directory for the app

File.applicationStorageDirectory
/data/data/app.appID/AppName/Local Store

User's home directory

File.userDirectory
/sdcard

User's document directory

File.documentsDirectory
/sdcard

User's desktop directory

File.desktopDirectory
/sdcard

Temporary storage directory

File.createTempDirectory()
Created in /data/data/app.appId/cache

Temporary file

File.createTempFile()
Created in /data/data/app.appId/cache
分享给朋友:
您可能感兴趣的文章:
随机阅读: