3

シンプルなテキスト ファイルをダウンロードする actionscript コードがあり、StageWebView に表示したいと考えています。ファイルがダウンロードされ、File.applicationStorageDirectory に正常に保存されます。コンテンツをコンソールに出力することはできますが、StageWebView でファイルを表示することはできません。私が読んだすべてによると、これはうまくいくはずです。ダウンロードしてローカルに保存したファイルを Android で表示できないのはなぜですか?

ユーザーがオフライン モードでファイルにアクセスできるようにする必要があるため、リモートの場所からファイルを開くように StageWebView を変更することはできません。

ユーザーがファイルにアクセスできないようにするため、sdcard にファイルを保存することもできません。

これは、私がやろうとしていることを示すサンプルテストです。Apache Flex 4.9.0 を使用し、Android 4.1.2 にデプロイしています

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" applicationDPI="160" >
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

    protected var webView:StageWebView = new StageWebView();
    public static const LOCAL_FILE_STORE:File = File.applicationStorageDirectory;

    protected function onClick(e:Event):void{

        trace("File.applicationStorageDirectory: "+ File.applicationStorageDirectory.nativePath);
        trace("File.desktopDirectory: "+ File.desktopDirectory.nativePath);
        trace("File.applicationDirectory: "+ File.applicationDirectory.nativePath);
        trace("File.documentsDirectory: "+ File.documentsDirectory.nativePath);


        var loader: URLLoader = new URLLoader();
        var request:URLRequest = new URLRequest("http://www.apache.org/dist/flex/4.9.1/README");
        loader.dataFormat= URLLoaderDataFormat.BINARY;
        loader.addEventListener(Event.COMPLETE, completeHandler);
        loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
        loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
        try {
            loader.load(request);
        } catch (error:Error) {
            trace("Unable to load requested document.");
        }
    }

    private function completeHandler(event:Event):void {
        var urlLoader:URLLoader = URLLoader(event.target);

        var writeFile:File = File.applicationStorageDirectory.resolvePath("test.txt");

        var writeStream:FileStream = new FileStream();
        writeStream.open(writeFile, FileMode.WRITE);
        writeStream.writeBytes(urlLoader.data);
        writeStream.close();

        //Test if we can output contents to console
        var readStream:FileStream= new FileStream();
        readStream.open(writeFile, FileMode.READ);
        var content:String= readStream.readUTF();
        trace("File Contents: "+ content);

        //Test if we can display file in stagewebview
        var sView:StageWebView= new StageWebView();
        sView.stage= this.stage;
        sView.viewPort= new Rectangle(0, 40, stage.stageWidth, stage.stageHeight);
        sView.addEventListener(ErrorEvent.ERROR, handleError);
        sView.addEventListener(Event.COMPLETE, handleComplete);

        trace("Loading file://"+writeFile.nativePath);
        sView.loadURL("file://"+writeFile.nativePath);
    }

    protected function onError(event:ErrorEvent):void
    {
        trace("UH OHHHH " + event);
    }

    private function ioErrorHandler(event:IOErrorEvent):void {
        trace("ioErrorHandler: " + event);
    }

    private function securityErrorHandler(event:SecurityErrorEvent):void {
        trace("securityErrorHandler: " + event);
    }

    private function httpStatusHandler(event:HTTPStatusEvent):void {
        trace("httpStatusHandler: " + event);
    }

    protected function handleError(event:ErrorEvent):void
    {
        trace("GOT ME AN ERROR: "+ event.errorID + "  "+ event.text);
    }

    protected function handleComplete(event:Event):void
    {
        trace("Done");
    }

]]>

4

1 に答える 1

1

したがって、Apache Flex 4.9.0 にバグがあるに違いありません。Flex 4.9.1 に更新すると、上記のコードが機能し始めたからです。

于 2013-03-01T18:10:20.207 に答える