FirefoxOS - get resource files from JS? - javascript

Is there a way to hold a large block of text, or images/videos, embedded in a FirefoxOS app, while directly accessing them from the app (similar to /res/raw/ in Android)? I don't see where the /data/ directory is being accessed in the example app.

There are many ways that you can do this:
Distribute your web app as a packaged app. In this scenario all your resource files are zipped up in a single file, available after install via a URL scheme described in the documentation.
The Application Cache allows you to instruct the browser to download files for offline use. I like Rob Hawkes' utility for generating appcache manifest files.
You can manage the data yourself by downloading the files via XMLHttpRequest and storing the data in an IndexedDB database or on the SD card via the DeviceStorage API.

I think that your best bet is the filehandle API, but more importantly keep in mind that a Firefox OS app is basically a website so you shouldn't be thinking as an android app that can carry it's media and so on.
Good luck

If you want to display images in a website you place images in the same root folder or sub folder. The same thing works with firefox OS.Place your images in your app folder and use them. If you want to use images from the mobile then you can use device Storage API .you can find the example here

Related

where is saved localStorage of an app's webview on the phone fileSystem?

I published a phonegap/webview application on the Play Store.
Now, that the app has some problems,
I need to access localStorage data to recover them, but I can't.
I can't because it's no more "debuggable", it's signed.
Wondering if I can access to those data through filesystem, mounting it via usb cable.
I guess under
/data/data/package_name (on a rooted phone)
I can find it.
Please share your experience if any.
You can use cordova file plugin to delete and read files and directories. Complete docs is available : https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/
In Android you can get the data from any file manager app: InternalStorage/data//files/

Cordova saving image downloads to www folder

I'm writing an app which house over 1000 small images in the www/images folder in my cordova app (am using Intel XDK for the build). The app needs to check for updates and download images that the user doesn't have, along with other content. I want the new images to be saved to the same folder as the existing images (www/images) and can't find anywhere how to do this. All I find is articles about Cordova saving camera images to gallery/camera roll etc.
The content will be run through and "injected" script which will save it to localStorage. I'm just struggling with the images.
As far as I know, you can't do this. The www folder is part of the app bundle, and is sandboxed to protect it from, well, writing. That's the same answer someone else got here: Cordova Write To WWW Directory (iOS).
You have to use the File API to write to one of the writable file areas available to the app. You can find some examples of how to do that here: https://github.com/johnwargo/apache-cordova-api-cookbook-code/tree/master/chapter10-file.
Some details from the book:
The Cordova File API provides an application with the methods it needs
to interact with the device’s local directory structure. The API
exposes methods an application can use to browse the file system,
read, write, copy, move and remove files. An application cannot access
just any part of the file system, only the temporary and persistent
file storage locations (described below) on a mobile device.
Cordova’s implementation of the File API is based in part on the W3C
File API: Directories and System specification
(www.w3.org/TR/file-system-api). Not all of the capabilities of the
W3C specification have been implemented, but the API provides the
essential capabilities most mobile developers will need.
An application would use this API to read and write files on the
device file system. An application might use one of the many available
storage options for web application to store application data, but
developers can also use the file system to persist application
settings or application data using the file system, writing text files
(in XML or JSON format for example) as needed while the application
runs. Additionally, remember that the Camera (Chapter 3) and Capture
(Chapter 4) APIs write their files to the file system, applications
use the File API to manipulate those files as needed.
Most smartphone provide applications with two different types of file
storage space. To store temporary files, the device exposes a
temporary storage location. For content and data that is integral to
the application’s operation and must remain available after the
application is closed and restarted the application should use
persistent storage.
In general, an application might use temporary storage for transient
data, data that’s written to the file system as part of a memory
management strategy or as swap space when analyzing or manipulating a
large amount of data. With temporary storage, the application can read
from and write to the storage area with impunity, creating and
deleting files as needed within the available storage limitations of
the device. The device OS may automatically empty temporary storage
when the application closes or the device reboots – freeing up storage
space for other applications.
Persistent storage on the other hand is more stable; the device OS
protects it during reboots and when the application closes. An
application’s persistent storage will be emptied by the OS only when
the application is uninstalled from the device.
In the sample application, the application’s UI exposes buttons that
are used to interact with the different file system types as shown in
Figure 10.1. As you can see from the figure, I used jQuery Mobile for
the application’s UI in order to simplify the code and let jQuery
Mobile deal with rendering file lists, transitioning between pages and
so on.

download an entire directory in a phoneGap (iOS) from a server?

i Am struggling for a about 1.5 days trying to find a solution without success.
i want to download an entire directory that web content (images, html, js and css) to the persistent storage in an iOS PhoneGap app. I tried compressing the files into a single file and was able to download it to the persistent storage but i was not able to extract it. to extract the file i've tried multiple things none of them worked for me:
zip.js
archive.js
and phonegap-plugin-ExtractZip https://github.com/fiscal-cliff/phonegap-plugin-ExtractZip
does anyone have an example "unzip" function that i can use. or is there a better way to transfer a whole directory from a server to a phoneGap app?
(i am using cordova-3-3-0)
thanks in advance,
You need to develop app that integrate with restful service. You can download sample code from my github account.
https://github.com/datomnurdin/service-finder-mobile

Download HTML to iOS persistent storage and load/navigate to it

I've just started using Phonegap with iOS and I'm wondering if there's a way to update the look of the application remotely (forgetting about App Store updates in this case).
I know that I can store data in a local database on the device and in files, but I'd like to navigate to that downloaded file. My app would start and check for updated HTML and JS files on my server. If there were none, it would continue to use the HTML already saved on the device. I don't want to navigate straight to a page on my server as Apple native APIs wouldn't work and I want the app to work offline too. I found this existing Stackoverflow question asking for something similar and persistent storage was mentioned by a commenter. I want to find out if it's possible to navigate to something in persistent storage.
Is it possible to download a HTML with Phonegap/Apache Cordova and then navigate to it?
The answer is YES.
You'll need a FileTransfer,
then store the file to the filesystem
You have to store the absolute path in the local-storage and navigate to it
I'am pretty sure, that this app will be removed from the apple-app store, because loading code from a server is prohibited.
Apple will remove this app from the store.

Phonegap: flexible iOS app update (No AppStore)

I have a Phonegap iOS app. My app is distributed privately, hence there is and there will be no usage of the app store. The app communicates with a homebrew middleware. In order to manage the app updates, I thought about doing something like:
-> On app start, check if a more recent version is available.
-> If yes then call a home-made Javascript module that will leverage the HTML5 file I/O API in order to update/create/delete files based on the output of the middleware.
In your opinion; is this solution reliable?
Are there any alternatives? (app store is completely out of the picture)
With a PhoneGap/Cordova app you normally load files from your local www folder. The problem with updating files at runtime is that you cannot write to the www location - you can only write to your app's 'documents' folder.
I assume you are using an Enterprise distribution since you are distributing without the app store. You could look at using something like TestFlight to distribute updates if you are happy for the users to have to go and check for updates.
You could also eliminate TestFlight and host the ipa files yourself, check for updates and then ask the user to download and install the update.
EDIT
It is not possible to write to the www folder with or without a plugin. This is due to iOS restrictions rather than PhoneGap/Cordova restrictions.
These links talk about distributing Enterprise apps over-the-air
http://developer.apple.com/library/ios/#featuredarticles/FA_Wireless_Enterprise_App_Distribution/Introduction/Introduction.html
IOS Enterprise Distribution Through OTA
Enterprise In-House App distribution
I was considering using the www folder as a bootstrap to download the actual app in a www folder in the document directory, and loading the index.html page from there (and the rest of the app)
I'm wondering if that would be an option
Of course the ObjectiveC UIWebView would point to the downloaded version if it exists
I know this is an old question, but the accepted answer is no longer correct. Here's a complete project showing how it can be done: https://github.com/ben-ng/phonegap-air
In short, the trick is to not write to the app bundle, but to the Documents directory.
There's an alternate service called Trigger.io. It is a lot like phonegap, but one of its' key features is that it lets you "reload" the app on the device, which is essentially what you're looking for, AFAICT.
So it seems that cordava can only load files that are in the app bundle. You cannot simply alter the webroot parameter to take the documents folder.
What you could do is use the FileReader API to read from the persistent store. This would mean you would have to create some sort of bootstrap html / javascript that is in the app bundle and create code that loads the content from the persistent store (which you can update yourself anytime you like)
This is a great place to start looking: Cordava File API docs

Categories