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.
Related
i'm beginner developer of phonegap android application developer. i'm in confusion. i want to make a photo gallery that work online(with internet). 1st: how can i embed my photo gallery with the application. 2nd: if user connection lost during checking photos there is not show the my app url (could not find URL http://www.domain.com/app/index.php) after connection lost it will go to on default error page of no internet connection.
my online application is in php how can i iframe that app in my native application.
phonegap android application developer help me. i'm very thankful to you for this.
Phonegap is not really a way to embed a full application inside an app. The app itself is its own website (sort of).
Your best direction is to create a PHP page on your sever that outputs an XML or JSON file of the images you are going to show THEN create a custom application using HTML / Javascript that pulls in the XML/JSON and parses it into your app. For best practise you should cache or store said files locally for when the device isn't connected to the network.
If I create a html 5 application for a phone (using phonegap or Icenium) that calls a webservice which needs a username/password, can a person look at the code somehow or is the JavaScript compiled away or obstructed in some manner?
Assume in this case that the url is in a javascript file with username and password.
Neither Phonegap nor Icenium (both based on Apache Cordova) obfuscate or compile the JavaScript code of your app.
You can take any Cordova app for iOS or Android and simply unzip the .ipa or .apk package to reveal the HTML, CSS and JavaScript code that powers the app.
If its a regular user, then most-likely not.
But if you are asking this question because you want to prevent someone that is skilled want needs to see your app for code. Then the answer is:
Nothing is safe in your clients device. Not sqlite database, not built-int storage , and not source code( weather its compiled or not);
When I compile my web app to a native iOS and Android app, how will it work? Will it be a regular web view that runs my app, which is in my server? Or it will place all the images, HTML and CSS files inside folders in the app project on Xcode and read them locally?
The latter. It will copy all files to the device, and run a webview which will load from the local directory. Think of it like you have some web files on your PC and point your browser to localhost to access them. It will load all the local pages/images even when offline, but you will face errors connecting to external resources unless online. Plenty of web apps are made without ever touching the developer's servers, also many times a simple restful solution will suffice.
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.
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.