Skip to main content

Posts

Showing posts from April, 2018

Downloading & opening a file in an Ionic app

If you search the Internet for examples to achieve the above, you'll get a number of resources that suggest using the cordova-file-transfer plugin. However, with Ionic 3+ and its native API, you can do this directly using a mix of Angular and Ionic  File API. Essentially, you need to use Angular HttpClient to download a URL as a Blob using the responseType option and then save the resultant Blob to a file on the device using the File API. Finally, open the saved file using the Ionic native FileOpener API. Here's the method in a provider that is used to download files from a website. Note that  this.http is an instance of HttpClient . /** * Download a file from the given url. * * Params: * url - the URL to download the file from * Returns: * A promise which upon resolution returns a dictionary * { * fileEntry: FileEntry, * type: The content-type string for the file * } */ download(url): Promise<{ fileEntry: Fi

Cordova build errors

Had this unusual errors crop up when building a cordova app for android. This started appearing after I installed cordova-plugin-file-opener2. ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:fontVariationSettings ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:ttcIndex Going through platforms/android/project.properties file, I realized that there was something quite odd about it. cordova.system.library.1=com.android.support:support-v13:26.+ cordova.system.library.2=me.leolin:ShortcutBadger:1.1.17@aar cordova.system.library.3=com.google.firebase:firebase-messaging:11.0.1 cordova.system.library.4=com.android.support:support-v4:27.1.0 cordova.system.library.5=com.android.support:support-v4:24.1.1+ cordova.system.library.6=com.android.support:support-v4:+ There were multiple versions of the same library being defined. I removed the last three lines -- library.4, library.5 & library.6, ensuring that t