简体   繁体   English

Android-仅在连接到PC时才能保存文件

[英]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.

相关问题 连接到PC时如何更新android中的文件 - how to update files in android when connected to PC Android:未连接到PC时服务表现不同 - android: service behaved differnat when not connected to pc 如何在不连接 PC 的情况下在设备中保存 android 运行时错误日志? - How to save android runtime error logs in device without connected to PC? 在调试模式下通过USB连接时,是否可以从Android在主机PC上运行.exe? - Can I run an .exe on the host PC from Android, when connected via USB on debug mode? Android活动/服务仅在手机连接到PC时有效 - android activity/service works only if phone connected to pc 连接Android手机时,使Java应用程序同步PC上的联系人 - making a Java application synchronize the contacts on the PC, when an android phone is connected to it 连接到PC时如何在Android手机上运行Shell命令? - How to run shell commands on Android phone when connected to a PC? 当Android设备未连接到PC时,React Native图像不显示 - React Native images do not show when android device is not connected to PC Android:检测PC上已连接的USB - Android: Detecting USB connected on PC android,调试未连接到PC,没有wifi? - android, debug not connected to PC, no wifi?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM