Category Archives: Apache Cordova

Post navigation

In order to avoid being surprised by the loss of your recorded audio file in iOS, you should be aware of how to properly record and store a media file in Cordova iOS.
Generally, in order to record an audio file in Apache Cordova, you can use the Cordova Media object as follows:

As shown in the code above, in order to record an audio file in Apache Cordova, you need to do the following:

Create a Media object (recordingMedia) and specify mediaFilePath (the path of the audio file), recordingSuccess (the success callback which will be called if the media operation succeeds), recordingError (the error callback which will be called if the media operation fails).

Start recording the audio by calling recordingMedia.startRecord().

After completing the audio recording, call recordingMedia.stopRecord() and then release the used Media object by calling recordingMedia.release()

In iOS, if you set mediaFilePath to the audio file name only without specifying any path (e.g "test.wav"), you may be surprised to find your audio file stored under the iOS app’s tmp directory (which is located under the iOS app’s sandbox directory). It is very important to be aware that the iOS app’s tmp directory content can be deleted automatically by iOS at anytime by iOS.

In order to avoid losing your app’s recorded files, just place the "documents://" prefix before the audio file name as follows.

Doing this will make the recorded audio file stored under the iOS app’s Documents directory. The iOS app’s Documents directory is located under the app’s sandbox directory and is suitable for storing the app files.

If you use Apache Cordova for developing your Android and Windows Phone 8 mobile apps, you may need to exit the app when the user clicks on the back button on the app’s home page, and to navigate back when the user clicks the back button and the current page is not the home page.

Note that back button usually exists in Android and Windows Phone 8 devices.

In order to do implement this behavior, you can implement the “backbutton” event handler after the “deviceready” event is triggered. This is an example to implement this in jQuery mobile.

Using navigator.app.exitApp(), you can exit your mobile app when the app user is in the home page. And using history.back(), you can navigate back to the previous page when the app user is in other pages.

One of the common issues when you use jQuery Mobile with Apache Cordova in many of the platforms especially in the old versions Android platform is that you feel that the transitions between the app pages are slow.

The solution for this problem is to disable jQuery mobile transition effects as follows when the jQuery mobile is loaded as follows.

I just get back from JMaghreb 2014 that was held in Casablanca, Morocco 05-06 November 2014. The conference organization was fantastic and there were a lot of attendees in the conference sessions.
I had the chance to present “Developing JavaScript Mobile Apps Using Apache Cordova” in 06 November, the session had many attendees and I was really amazed by the energy, enthusiasm, and responsiveness of the attendees during the session.

What this book is about

Mobile development is one of the hottest trends and a staple in today’s software industry. Almost every popular website today has its own equivalent mobile application version to allow its current users to access its functions from a mobile device. However, developing mobile applications requires a lot of effort and a wide skill set from mobile developers. Whether you are developing a mobile app for an iPad or on a Windows Phone, there is a requirement to learn the specific languages and technologies for that device. This is where the glory of Apache Cordova shines. As a set of device APIs for building cross-platform mobile applications using HTML, CSS, and JavaScript, the apps developed using JavaScript APIs are easily portable to other device platforms, as well as being consistent across devices and built on web standards. As a result of this, you will find that your development costs and efforts are sharply reduced, whilst increasing the readability and maintainability of your code, as you make use of only one popular programming language: JavaScript.

This is the learning resource to use when you want to efficiently develop your own native mobile applications using Apache Cordorva as the platform that uses HTML, CSS, and JavaScript. In order to develop neat-looking mobile applications, this book also utilizes jQuery mobile. jQuery mobile is one of the best mobile web application frameworks that allows web developers to develop web applications that are mobile friendly.

We start by developing a simple sound recorder mobile app. We then configure this app to work on Android, Windows, and iOS. Then you will learn how to use the different APIs provided by Apache Cordova and how to develop your Apache Cordova custom plugins.

You will then learn how to develop, run, and automate tests using Jasmine. At the end, you develop a “Mega App” where you will learn in details how to design, develop, and deploy a real cross-platform Apache Cordova application that works in Android, iOS, and Windows Phone 8.

After finishing this book, you should be able to develop your mobile application on the different mobile platforms, using only JavaScript, without having to learn the native programming languages of every mobile platform.

What this book covers

Chapter 1, An Introduction to Apache Cordova, teaches what Apache Cordova is and the differences between mobile web, mobile hybrid, and mobile native applications. You will also know why we should use Apache Cordova, along with the current Apache Cordova architecture, and finally, the chapter offers an overview of Apache Cordova APIs.

Chapter 3, Apache Cordova Development Tools, explains how to configure your Android, iOS, and Windows Phone development environments. You will also learn how to support and run your Sound Recorder mobile application on both iOS and Windows Phone 8 platforms.

Chapter 4, Cordova API in Action, dives deep into Apache Cordova API, and you will see it in action. You will learn how to work with the Cordova accelerometer, camera, compass, connection, contacts, device, Geolocation, globalization, and InAppBrowser API by exploring the code of the Cordova Exhibition app. The Cordova Exhibition app is designed and developed to show complete usage examples of the Apache Cordova core plugins. The Cordova Exhibition app supports Android, iOS, and Windows Phone 8.

Chapter 5, Diving Deeper into the Cordova API, continues to dive into Apache Cordova API by exploring the remaining main features of the Cordova Exhibition app. You will learn how to work with Cordova media, file, capture, notification, and storage API. You will also learn how to utilize the Apache Cordova events in your Cordova mobile app.

Chapter 6, Developing Custom Cordova Plugins, dives deep into Apache Cordova and lets you create your own custom Apache Cordova plugin on the three most popular mobile platforms: Android, which uses the Java programming language, iOS, which uses the Objective-C programming language, and Windows Phone 8, which uses the C# programming language.

Chapter 7, Unit Testing Cordova Apps Logic, explains how to develop JavaScript unit tests for your Cordova app logic. You will learn the basics of the Jasmine JavaScript unit testing framework and understand how to use Jasmine in order to test both the synchronous and asynchronous JavaScript code. You will learn how to utilize Karma as a powerful JavaScript test runner in order to automate the running of your developed Jasmine tests. You will also learn how to generate the test and code coverage reports from your developed tests. Finally, you will learn how to fully automate your JavaScript tests by integrating your developed tests with Continuous Integration tools.

Chapter 8, Applying it All – the Mega Application, explores how to design and develop a complete app (Mega App) using Apache Cordova and jQuery Mobile API. Mega App is a memo utility that allows users to create, save, and view audible and visual memos on the three most popular mobile platforms (Android, iOS, and Windows Phone 8). In order to create this utility, Mega App uses jQuery Mobile to build the user interface and Apache Cordova to access the device information, camera, audio (microphone and speaker), and filesystem. In this chapter, you will learn how to create a portable app that respects the differences between Android, iOS, and Windows Phone 8.

I just get back from ApacheCon North America that was held in Denver, CO, USA 07-09 April 2014. The conference organization was fantastic and there were a lot of attendees in the conference sessions.

I had the chance to present “Developing Native Mobile Apps using JavaScript” in 07 April, the session had many attendees and I was really amazed by the energy, enthusiasm, and responsiveness of the attendees during the session.

The session went great and I was glad to give a free copy of my JavaScript Unit Testing book to one of the attendees who answered a JavaScript quiz at the end of my session.

If you use jQuery Mobile with Apache Cordova, you may find a little bit slowness in the transitions between pages of your mobile application. Actually, I had this issue with one of my Apache Cordova applications, and after spending sometime investigating the problem, I found that the solution is to disable jQuery mobile transition effects as follows:

Disabling transition effects will dramatically boost your app’s transition performance. I hope that this advice can be helpful to you in order to enjoy developing your cross-mobile apps using the wonderful Apache Cordova library.

Note: This advice targets jQuery mobile 1.4 (and older versions), I wish that this slowness issue will be fixed in the future versions of jQuery mobile.