如何在AS3 / Flex手机打开的应用程序存储目录中新写入的文件?应用程序、中新、文件、目录

2023-09-08 14:58:07 作者:Transparent(透明)

林工作的一个应用程序(弯曲4.12 SDK,使用flashbuilder 4.5,在Android的HTC One主要用于创建iOS和Android,测试的应用程序).​​.....和现在用的相机捕捉到一个文件中...林则保存该图像应用程序存储目录,我想在默认的Web浏览器中打开图像或触发本地对话框(Android用户)可以选择他们所选择的网页浏览器...它是如何打开心不是真的很重要,现在 - - 进出口主要是想只是'访问'它与设备和'负荷'它超出了我的AIR应用程序...

Im working on an app (flex 4.12 sdk, using flashbuilder 4.5, creating an app for ios and android, testing on an android htc one primarily)... and am using the camera to capture a file... Im then saving that image to the application storage directory, and I want to open the image in the default web browser or trigger a native dialog (android users) to choose the web browser of their choice... how it opens isnt really important right now -- Im mainly trying to just 'access' it with the device and 'load' it outside my air app...

继承人的code,我有:

heres the code I have:

                var fs2 : FileStream = new FileStream();
                fs2.addEventListener(Event.CLOSE, fileCompleteHandler); 
                var targetFile : File = File.applicationStorageDirectory.resolvePath("test.jpg");
                fs2.openAsync(targetFile, FileMode.WRITE);
                fs2.writeBytes(myBMDByteArray,0,myBMDByteArray.length);
                fs2.close();

和事件侦听器检测到接近新创建的文件中:

and for the event listener that detects the close of the newly created file:

                function fileCompleteHandler(e:Event):void {
                    trace('File saved.');
                    trace('exists? ' + targetFile.exists);
                    trace('the url: ' + targetFile.url);
                    trace('path: ' + targetFile.nativePath);
                    navigateToURL(new URLRequest(targetFile.url));
                }

我得到以下信息回程从这个监听器

I get the following info back from this listener

文件保存。 的存在?真正 的网址:应用程序存储:/test.jpg 路径:/data/data/air.com.xxxxx.apptesting.debug/com.xxxxx.apptesting.debug/Local店/ test.jpg放在

...而问题是,navigateToURL不能访问该文件的存储位置(该协议在浏览器中显示为文件:///数据/数据​​/ air.com / XXX ...)

... and problem is that navigateToURL cant access the location where the file is stored (the protocol shows in browser as file:///data/data/air.com/xxx... )

我该如何使用navigateToURL以访问这个新创建的文件在网络浏览器或其他本机应用程序与文件(其.JPG文件)设备同伙?我也曾经有过在加入新创建的图像的相机胶卷成功,但不可能弄清楚如何,然后在本地相机胶卷打开刚刚保存的图像或其他应用程序的设备选择或presents用户为.JPG格式。

how can I use navigateToURL to get access to this newly created file in the web browser or whatever native application the device associates with the file (its a .JPG file)? I also have had success in adding the newly created image to the camera roll but couldnt figure out how to then open that newly saved image in the native camera roll or whatever app the device chooses or presents to the user for the .jpg format.

我可以显示用户在我的应用程序中的图像通过引用位图数据很好,我只是想给物理文件的用户访问,即时通讯创造自己的设备上。

I can show the user the image INSIDE my app by referencing the bitmap data fine, I just want to give the user access to the physical file that Im creating on their device.

我甚至已经在(通过的URLLoader)发布的位图数据为base64编码,然后创建在服务器端和加载该URL的文件,但编码和行程,并从服务器,为用户提供了成功的形象加大量的开销,这需要一点时间太长,我想避免这种拉长的过程。

I even have had success in posting (via urlLoader) the bitmap data as base64 encoding and then creating a file on the server side and loading that url but the encoding and trip to and from the server to give the user the image adds a lot of overhead and it takes a little too long and I'd like to avoid that elongated process.

感谢您的帮助,任何人都可以提供 - 让我知道,如果我需要更具体的在任何这

Thanks for any help anyone can provide - let me know if I need to be more specific in any of this.

推荐答案

解决这个问题...我是能够存储/使用写我的文件中documentsDirectory:

Solved the issue... I was able to store / write my file in the documentsDirectory using:

var targetFile : File = File.documentsDirectory.resolvePath('test.jpg');

然后

navigateToURL(new URLRequest(targetFile.url));

而现在能正常工作。希望这可以帮助别人!看来,存储目录应该工作,但到现在为止我只写入和读取存储在那里的​​文件...也许打开人们必须将其复制到安全的位置在文件系统中的文件(即SD卡?) ...将移动到IOS测试在现在 - 希望在OS一切运作良好。感谢所有谁遥相呼应这一点。

And this works fine now. Hopefully it helps someone else! Seems that the storage directory SHOULD work but up until now I've only written to and read files stored there... maybe to open the files one HAS to copy it to a 'safe' location in the filesystem (i.e. sd card?)... will move on to test in ios Now - hope all works well in that OS. Thanks all who chimed in on this.