• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Differences between emulators

New Here ,
May 31, 2011 May 31, 2011

Copy link to clipboard

Copied

Is it possible that an application that works on all the emulators for FB 4.5 does not run on the Android SDK emulator?

I'm having problems with the stagewebviewbridge.

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 31, 2011 May 31, 2011

Copy link to clipboard

Copied

The problem seems to be about reading and writing files.
Here's the code:

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

   xmlns:s="library://ns.adobe.com/flex/spark"

   creationComplete="fileinit(event)">

<fx:Script>

<![CDATA[

import mx.events.FlexEvent;

private var _tmpFile:File = new File();

private var _fileStream:FileStream;

protected function fileinit(event:FlexEvent):void

{

_fileStream = new FileStream();

_tmpFile.nativePath = File.applicationDirectory.resolvePath('tmp.cfg').nativePath;

_fileStream.open(_tmpFile, FileMode.WRITE);

_fileStream.writeUTFBytes( 'firstRun=true' );

_fileStream.close();

}

protected function readFile(event:MouseEvent):void

{

// get original file contents

_fileStream.open(_tmpFile, FileMode.READ);

var originalFileContents:String = _fileStream.readUTFBytes(_fileStream.bytesAvailable);

_fileStream.close();

tArea.text = originalFileContents;

}

]]>

</fx:Script>

<fx:Declarations>

<!-- Place non-visual elements (e.g., services, value objects) here -->

</fx:Declarations>

<s:Label left="20" top="20" text="Label"/>

<s:Button x="20" y="51" label="Button" click="readFile(event)"/>

<s:TextArea id="tArea" y="137" right="20" height="70"/>

</s:Application>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Jun 01, 2011 Jun 01, 2011

Copy link to clipboard

Copied

I don't think applications can write into their installation folder. There's a separate storage folder. Try accessing that path via File.applicationStorageDirectory. You should be able to have write into that.

P.S: I'm guessing running it on an actual device will have the same problem.

-Anirudh

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 16, 2011 Jun 16, 2011

Copy link to clipboard

Copied

I have find some time and machine ( Android ) to test with...

As you comment the problem with Android is that we can't write to the application directory as is really a "pseudo-zip" and the nativePath of the "app:/" returns blank.

As you say the workarround is to move the cache filesystem to the File.applicationStorageDirectory. But this implies that you double the space used by your content. For little projects with only a few files there is no major problem, but imagine an app that contains a huge amount of videos....!!!!!!

The problem with the communication is solved deleting the window.alert rewrite code from the StageWebViewBridge.as and StageWebViewBridge.js.

Seems that the Android webkit don't like this!!! grrr

DELETE THIS LINES FROM StageWebViewBridge.as and StageWebViewBridge.js.
// workaround to fix application crash when window.alert is called directly from AS3         
    window.alert = function(native)
    {
            window.nativeAlert = native;
            return function(str)
            {
            setTimeout('window.nativeAlert("'+str+'");',10);
            }
    }(window.alert);


Anyway, I am testing some other methods for do a good workarround.... 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 16, 2011 Jun 16, 2011

Copy link to clipboard

Copied

It doesn't double the space used... this solution is the normal way to store data. In fact, this is the only way to store data that will work on all OS...

What is your problem? You have assets included in the package that you want to modify and save again?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 16, 2011 Jun 16, 2011

Copy link to clipboard

Copied

Hi,

Yes, this is the exact case... imagine you have an app that will show some big mp4 videos with the stagewebview class.

The stagewebview.loadURL method docs says:

"The URL can use the following URI schemes: http:, https:, file:, data:, and javascript:.            Content loaded with the file: scheme can load other local resources."

and

"On Android, the nativePath property of a File object pointing to the application directory is an empty       string. Use the url property to access application files."

From this, its imposible to access using the file:/ protocol to the assets you have added to the app  as you can only point to the files with the app:/ protocol.

The only workarround I know ( is working with some modification in my StageWebViewBridge class ) is to copy the entire resources to the applicationStorageDirectory, and then, you can safe read these documents use the file:/ protocol.

But as I comment this workarround implies douplicate the space used in the html assets.

Other workarround will be to download the assets from the net in the app first run, but this implies you have a hoting server to host the files...

If you know another way, ideas to overcome this problem please say me as I will test if it can fit with the StageWebViewBridge class.

Anyway, as some developers use net resources with the StageWebViewBridge class, I am preparing a StageWebViewBridgeLitte without the cache filesystem.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 16, 2011 Jun 16, 2011

Copy link to clipboard

Copied

Someone found a trick to get the nativePath from the app install directory... Try it on a device to see if you have enough permission to access the file by that url.

http://www.mikechambers.com/blog/2008/11/06/getting-the-file-uri-of-a-file-in-an-air-apps-install-directory/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 16, 2011 Jun 16, 2011

Copy link to clipboard

Copied

Yes, I know this... This is the way StageWebViewBridge class works... but this "hack" is unuseful as:

"On Android, the nativePath property of a File object pointing to the application directory is an empty       string. Use the url property to access application files."

The problem with the apps in android is that the app with its contents is packaged as a .apk ( really a zip file ) and the app works inside the "zip".

Then is imposible to access the files with the file:/ protocol as the files really don't exist in the filesystem.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 28, 2011 Jul 28, 2011

Copy link to clipboard

Copied

LATEST

Hi,

Someone found a solution to load properly local HTML files on Android ?

I try to load a html file with a video inside, but I don't success.

If I copy the file in other place, I can load the HTML but my video is unvailable (local file)

How can I do that ? Do I need to use HTML 5 <video> tag ? which path I need to use ?

If someone has an example (its ok on IOS)

Thx

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines