[英]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. 我正在开发一个应用程序,用户可以在某些时候将图像文件保存到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.
当手机连接到PC时,一切正常,但是当我断开手机并启动应用程序时,文件保存不起作用。
I am guessing that I should use a different path to save when not connected to a PC? 我猜想在不连接PC时应该使用其他路径保存吗?
my current path is 我当前的路径是
"//mnt/sdcard/DCIM/Camera/image"+Math.random()*10000+".jpg"
I am using pure AS3 AIR to develop. 我正在使用纯AS3 AIR进行开发。
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: Android应用程序的存储目录如下:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.