FLEX手机:无法读取"saved"安卓平板电脑上本地文件系统上的图像



我正在将一些图像下载到我的应用程序中,以便可以在不消耗任何带宽的情况下显示它们。我用来在我的安卓设备上存储图像的代码如下:

        var file:File = File.applicationDirectory.resolvePath(fileName);
        if (file.exists)
        {
            file.deleteFile(); //delete it if exists
        }                                   
        var fileStream:FileStream = new FileStream();           
        fileStream.open(file, FileMode.WRITE);          
        fileStream.writeBytes(data, 0, data.length);            
        fileStream.close();     
        var showLocalPath:String = file.nativePath;

为了显示图像,我使用以下两个示例:

<s:BitmapImage id="iconStateImage" source="{appContext.CurrentState.IconImage}"/>
<s:Image id="backgroundStateImage" left="0" right="0" top="0" bottom="0" source="{File.applicationDirectory.resolvePath(appContext.CurrentState.BackgroundImage)}"/>

appContext.CurrentState.IconImageappContext.CurrentState.BackgroundImage都与前fileName具有相同的路径。即使我尝试使用完整路径(第二种情况)或短路径(第一种)加载图像,我也无法显示它。

我已经在项目上设置了写入权限。

有人可以帮助我吗?提前谢谢。

问候

塞巴斯蒂安

File.applicationDirectory是只读的;您需要改用File.applicationStorageDirectory

另请参阅如何删除应用程序目录中的文件?和 Flex 文件文档。

然后添加"应用程序存储:/"在图像路径之前:

<s:Image id="backgroundStateImage" source="app-storage:/{appContext.CurrentState.BackgroundImage}"/>

相关内容

最新更新