O'Reilly logo

PhoneGap 4 Mobile Application Development Cookbook by Zainul Setyo Pamungkas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Saving a file in the device storage

Thanks to the ability to traverse, read, and write to the device filesystem, an application can write a file to either a specific, predefined location or a location chosen by the user within the application.

How to do it...

We will allow the user to enter a remote URL for a file in a textbox to download and save that file in their mobile device:

  1. Firstly, create a new PhoneGap project named storage by running the following line:
    phonegap create storage com.myapp.storage storage
    
  2. Add the devices platform. You can choose to use Android, iOS, or both:
    cordova platform add ios
    cordova platform add android
    
  3. Add the file and file-transfer plugins by running this line:
    phonegap plugin add org.apache.cordova.file
    phonegap ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required