Umer Pasha Blogs

Simplest example of Phonegap testing bar code, camera picture, camera video and geo location

When I started using phonegap, It took a while even with the available documentation to get the app going. I made this example project to trim it to bare minimum but still perform the most sought after functions on any mobile device.

For build purposes i am using Create a test account that allows for one app.

You will probably also need a github account as it makes it very simple to pull updated code from repository when making a build on

I am testing this on an android device as it is just easy to update and download app for testing using android. For Apple/iOS, you will need to have a key.

The functionality has been tested on latest versions of Android, iOS and WinPhone.

To understand this tutorial, you should already know:
Some knoweldge of HTML and HTML5
Working knowledge of Javascript
Some idea what phonegap really is

It has examples of camera function, video recording and geo location.

The only files you have to look into are in www folder.

Config.xml has all the plug-ins defined:

Example: <gap:plugin name=”org.apache.cordova.core.geolocation” version=”0.3.10″ />

Index.html has all the UI and buttons to invoke different functions along with DIVs to show results

Js/app.js has all the javascript code.

I wait for device to be ready to listen to events:

Example: document.addEventListener(“deviceready”, onDeviceReady, false);

If an event is fired (touch end of a button), separate functions are called:

Example: document.querySelector(“#startGLoc”).addEventListener(“touchend”, startGLoc, false);

On event completion, result is updated:

Example: GLocDiv = document.querySelector(“#GLoc”);
Code location is on GitHUb:

Build can be accessed from this QR code:

1 Comment »

Simplest Phonegap Barcode reader example

Created a small app last night to read barcodes.


Nothing fancy. Just a button to invoke the barcode reader camera and then returns the barcode number along with the barcode standard.


You can get it here:



Checked on iPhone 5S and Android Kit Kat.


I am only using an html file and a js file along with the config.xml.


You can get the code from my github repository. You can remove the resource files from config.xml. I just got it from the base template.




  1. To add the plugin , in Config.xml you need to have:

<gap:plugin name=”com.phonegap.plugins.barcodescanner”/>


  1. Write the following javascript to listen for an event (button click) and then start the scanner


</p><p>var resultDiv;</p><p> </p><p>document.addEventListener("deviceready", init, false);</p><p>function init() {</p><p>               
 document.querySelector("#startScan").addEventListener("touchend", startScan, false);</p><p>               
 resultDiv = document.querySelector("#results");</p><p>}</p><p> </p><p>function startScan() {</p><p> </p><p>               
 cordova.plugins.barcodeScanner.scan(</p><p>                               function(result) {</p><p>                                               
 var s = "Result: " + result.text + "&lt;br/&gt;" +</p><p>                                               "Format: " + result.format + "&lt;br/&gt;" +</p><p>                                               "Cancelled: " + result.cancelled;</p><p>                                               
 resultDiv.innerHTML = s;</p><p>                               
 },</p><p>                               function(error) {</p><p>                                               
 alert("Scanning failed: " + error);</p><p>                               
 }</p><p>               );</p><p> </p><p>}</p><p> </p><p>







Show emails in stock Android email client

Ok, finally I was able to show emails in stock Android email client, after 4 or 5 days of hit and trial. This is how you do it…

I recently switched from to

I have tested this on my HTC Sensation 4G running ICS

In stock android email client, create a new account for Exchange Active Sync.

Use \[address] for “domain” and “username” e.g. “\”
enter server as “”

Leave a comment »

Listing installed APKs in an Android system

Following code lists all the APKs installed in the Android System. I have checked this with ICS 4.0.1 and works fine. Pre-installed applications are in /system/app folder. User installed applications are in /data/app. Though this mostly works, user installed applications will probably only show up if you have a rooted device.

 public class Testing extends Activity {
    private static final String TAG = "TEST";
    public void onCreate(Bundle savedInstanceState) {
        File appsDir = new File("/data/app");

        String[] files = appsDir.list();

        for (int i = 0 ; i < files.length ; i++ ) {
            Log.d(TAG, "File: "+files[i]);


Leave a comment »

SpeakToIt Android giving me issues!

So today, I installed SpeakToIt on my android phone. Supposedly its Android’s answer to Siri. Funnily…. it worked for a while and then just stopped. Showing me an error “I am not sure what happened but I will talk to my creators and they will fix it ASAP”. I tried everything….. force close, uninstall, reboot, cold boot……. everything with all different permutations!

Turned out, the problem was with Speech Synthesis that it made me install initially. I removed it…. and removed the 2 cache processes for it… and now it works fine. Well actually i am not sure…. but its one of the 2 things… either uninstall speech synthesis (SpeakToIt works fine even after I uninstalled SS, so it really cant be needed that much) or it was the cached process that needed to be closed.  For that, go to settings, applications, SpeakToIt and click clear cache. Do the same for running processes.

Leave a comment »

Create playlists on android

I have around 60 GBs of music with me. I did not want to create playlist using HTC Sensation UI as it will take me more time to set it up then listening to it!

I guess android does not create files for playlists, There is no set location for playlist files.

Here is what i did.

Step 1: Connect your phone to the computer as a hard drive.

Step 2: Create a folder in SDCard (default location if connected as harddrive) called “Playlists”

Step 3: Downloaded Winamp 2.81 Lite from here.

Step 4: Installed Winamp 2.81 to the computer.

Step 5: Copied all the music folder to a folder in SDCard called “Music” on cellphone.

Step 6: Ran Winamp on computer and in playlist clicked “List Options” >> “New List”

Step 7: In Winamp, clicked “Add” >> “Add Dir” and added the music folder on the cellphone. You should see all the songs in the playlist now.

Step 8: In Winamp on computer and in playlist clicked “List Options” >> “Save List” and save the list to the “Playlists” folder we created in android.

Step 9: You should be able to see the playlist now in stock android music player. Done!

Leave a comment »