as3 AIR for android - Application-sandbox content ERROR - android

THE GOAL:
I am trying to allow externally loaded swf files communicate with each other that are locally loaded from the device. I need to be able to have access to vars and functions and objects. I have accheived this while loading swf content from the web here: as3 externally loaded swf from network to control externally loaded swf from network
BUT WHEN I GIVE THE USER THE OPTION TO LOAD FROM DEVICE OR FROM ONLINE... The device swf files can't communicate with each other. Specifically the loaded swf can not get info from its parent.
Below is the code that works when loading from online:
var InsideConent:Object = this.parent.parent as Object; //// GIVES ACCESS TO "Content.swf"
var ItWorksNow:Sprite = MovieClip(InsideConent.TWO.content).ChildInTWO; ///
The device doesn't like this code:
Security.allowDomain("*");
But when run online it works fine. Below is the error I get when I run it locally loaded from the APP package.
THE ERROR:
SecurityError: Error #3207: Application-sandbox content cannot access this feature.
at flash.system::Security$/allowDomain()
at Products_fla::MainTimeline/frame1()
Cannot display source code at this location.
THE QUESTION:
Is there anything I can do to make allow security domain to work locally on an AIR FOR ANDROID device so I don't have to change my code? - thanks

If you put a try catch around that line it won't throw an error if it fails. And this way when your code will work on the web and as an app. (apps don't need to allowDomain b/c they can download everything by default and that is why it fails.)
try {Security.allowDomain("*");}catch (e) { };

From my experience you can load remote swfs from another domain that is configured correctly with the crossdomain xml.
something like: https://developers.arcgis.com/flex/guide/using-crossdomain-xml.htm
You can load swf with code,
but if you try to access the stage for example it will fail.
Also, if in your original project (hosted all on a web server, you used common static variables or singeltons, it will not succeed.
My solution was adding functions on those files which receive the objects I needed to work with.

As far as I know you can't execute code from loaded swfs in AIR, you can still use multiple swfs to dislay assets but any code will give that error.

Related

How do you setup crosswalk on android to load files from the local external storage?

I am developing an app on Android using Crosswalk that show files that I need to download from a web service. I would rather download the files to the external storage. But when I try to load them into the Crosswalk WebView I get a "Not allowed to load local resource:" error. I tried opening them directly and through a json manifest with csp properties like this (and some variations):
"csp" : "default-src 'self' file:// http:// https://"
My current setting are rather permissive:
mXWalkView.getSettings().setAllowContentAccess(true);
mXWalkView.getSettings().setAllowFileAccess(true);
mXWalkView.getSettings().setDomStorageEnabled(true);
mXWalkView.getSettings().setAllowFileAccessFromFileURLs(true);
mXWalkView.getSettings().setAllowUniversalAccessFromFileURLs(true);
mXWalkView.getSettings().setJavaScriptEnabled(true);
But still no success. Any ideas? Is this even possible?
UPDATE
To clarify and so that it doesn't get lost in the comments:
I am using the following code to load the file:
String url = "file:///storage/emulated/0/wh_files/index.html";
mXWalkView.load(url, null);
OK, I was finally able to track down the problem and it didn't have anything to do with the implementation. There seems to be a hardware problem on the device and the file that I wanted to load was corrupted.
I guess that the important lesson to learn is that the "Not allowed to load local resource:" error not always means what it says.

Make app generated content show in stock android Downloads app

We are working on an android app that generates PDFs based on app contents on users' request. We are providing an option to launch an email agent and attach the generate PDF, but we also want the user be able to view the document later at any time. On android, there are no stock file explorer, so our first thought was to show on the stock Downloads app's file list. We've tried the following two methods but without luck.
We firstly tried to save the PDF to the default download folder (given by calling Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)) and invoke media scanner, but the file doesn't show up in the Downloads app's list. It's shown in Adobe Acrobat's local document list though.
After some research, it seems that the Downloads app would only show files that downloaded though DownloadManager, so we tried to generate the PDF in a temporary directory and call DownloadManager to download it, but, somehow expected, it complains that we can only download via HTTP(S), so this approach isn't working as well.
Is there any other solution?
well if you have to provide access to the document without any file explorer app, i think your approach is correct it to allow to store it in the Download lists. To achive this you can use Nanohttpd in your application to host your pdf document and then invoke the DownloadManager download action using HTTP(S) to your webapp (you will have to create a small webapp to handle the download request) hosted on localhost server.

HTML5 Android Phonegap Web app not working offline with cache manifest

I have a simple web app built with Phonegap and Android that call external ressources (js, css, html) from server instead of storing it in Phonegap assets folder. I prefer using external ressources because my server can deliver html pages taking in charge internationalization.
This web app work fine on my android device when WIFI is on but it fail when stopping WIFI. My index.html file delivered by my server contain a valid manifest file with correct mimetype ('text/cache-manifest') that list every files the app need to work.
My Android Activity class is supposed to have caching enable:
this.appView.getSettings().setDomStorageEnabled(true);
this.appView.getSettings().setAppCacheMaxSize(1024 * 1024 * 15);
String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
this.appView.getSettings().setAppCachePath(appCachePath);
this.appView.getSettings().setAllowFileAccess(true);
this.appView.getSettings().setAppCacheEnabled(true);
It may worth mentionning that my app use ajax call with urls like /aaa/bbb/ to call web pages from server and I don't know if that may be the problem (l'm not calling physical pages directly like index.html)... However, this web app work well in desktop browser (Google Chrome) when offline...
Any idea what more can I do to enable this HTML5 cache feature on my Phonegap app?
Thanks a lot
After playing around for a while I get it to work. Here is some points you should verify when stucked with this type of caching problem:
Take care about url parameters passed with GET method... I was passing parameters when navigating between pages of my app and those parameters was making my urls different from the ones in manifest file making cache to fail.
When testing offline mode on my phone, I was only shutting down the WIFI thinking this was enough to trigger cached version of my app but it was not... As I was testing my app published under a local network IP (like 192.168.2.11), it appear that my app was trying to reach that IP trough the 3G network that was still ON... So use airplane mode when testing offline.
Not sure if this one was necessary as I read it on some others threads but I renamed my manifest file to cache.manifest.
Regards
Apparently you need "to fix the Android Shell Native App to enable HTML5 caching".
If you haven't already, please check out: http://tmkmobile.wordpress.com/2012/03/04/html5-offline-solution/
I am developing a similar system. What I did was I created the Phonegap webpages and stored them in the www folder of my WAMP server. Then what I do is I basically super.LoadURL("insert_ip_address_here/insert_name_of_folder_where_webpage_is_located") in the onCreate method and this loads the phonegap application perfectly (yes all you need is just only line of code in the Android app itself). However you still have to make sure that the config.xml, manifest and all configurations needed for phonegap are properly done (for instructions on this see https://www.adobe.com/devnet/archive/html5/articles/getting-started-with-phonegap-in-eclipse-for-android.html).
Let me know if this the path you choose to pursue. I can provide extra support with things like making the ip-address (in the line super.loadurl(...)) dynamic for the local system using multi-casting, etc.

Android web application on cloud storage

I have a cloud storage website and I want to create an Android application for that website.
I tried 2 methods.
First Method
Using Phonegap to open a remote website which handles everything and its built-in PHP so everything works fine. But a Cloud Storage app must allow uploading and downloading. In Phonegap I can upload through the website but can't download directly to local storage. It can only be done locally if my website is in the local www folder. Also in this way API of Phonegap can't be used either. If I download any file the browser opens up, in this case.
Second Method:
I tried to use Phonegap locally and just create an API of my cloud storage website so that locally with the help of jQuery ,Ajax so that I can post data to the remote URL, but that can't be done due to the Same Origin policy. I may receive the JSON data of files and show but can't log the user in and other features. :( Again a problem.
What else can I do? Is there any other method or solution you can provide me regarding these two methods or any alternative method I can use?
Depending on the kinds of data you're talking about there are several alternatives.
You're describing a cloud storage app (I'm assuming like drop box or Google drive right).
Therefore you'll want to write to the file system instead of some kind of database (locally ofc)
I would therefore check out the following api docs;
http://docs.phonegap.com/en/2.1.0/cordova_file_file.md.html#File
Examples are there too.
PS ive had same origin problems in development, but they seem to go away in production, try testing there too.

How to play local video files in a browser

Am looking for the way to play video inside my android browser locally. There may be two or more video's in a local page (like facebook contains video's).
Can anyone please help me out..
Without actually reading about the specifics of the Android built in browser I would safely say, you can't. Well, if you run a local html file it might work, but if you intend to have an external page from which you can play local videos it shouldn't work. I say shouldn't because in the early days of browsers some of them actually did give you access to the local file system. Javascript for example could use file://, something I used myself for image previewing before upload. But this was a major security concern and all modern browsers prevent this.
The difference is if you run a local file or a file on your own local web server. Since then, your local file system is actually part of the web servers file system and the web server can serve your local files.

Categories

Resources