Tag Archives: Android

Installing The SQLite PhoneGap Plugin via the CLI

30 Apr 2014

For some reason I had issues trying to install the PhoneGap SQLite plugin for Android on my Windows 8.1 laptop using the CLI. Attempting to run the install resulted in a Command failed: fatal: could not create work tree dir error. After some fruitless searching for a solution I took another look at the error message and thought that maybe the problem would be something simple to resolve.

This type of CLI command usually works:

$ phonegap plugin add https://github.com/brodysoft/Cordova-SQLitePlugin.git

As mentioned this resulted in the following error:



The key to solving this is in the error message – apparently the temp path can’t be created…. so… create it!

Using Explorer navigate to this path:

  • C:\Users\[YOUR USER NAME]\AppData\Local\Temp

Note that “AppData” is likely a hidden folder – just enter the path (use your own user name where appropriate). For example:




Once in the Temp folder create the necessary directories to recreate the following path:

  • C:\Users\[YOUR USER NAME]\AppData\Local\Temp\plugman\git

And once again run the CLI command for installing the plugin. This time everything runs without error:




Android 4.1.2/PhoneGap 3 AdjustPan with Fullscreen Theme

17 Mar 2014

If you’re reading this you’ve been stung by the AdjustPan bug in PhoneGap – this is where the softkeyboard appears when one of your text fields gets focus but the view does not shift up to reveal the field that you’re attempting to type into. Setting the windowSoftInputMode in your application manifest to “adjustPan” should in theory accomplish this. Apparently no amount of XML / main activity settings will create the desired result so the average PhoneGap dev – one who is not a Java Developer – has to rely on whatever work-around the community decides to share.

Go here to read about the expected behavior of windowSoftInputMode’s “AdjustPan” setting. You may also want to read about the bug. Various posts I have read say that this bug seems to manifest itself because PhoneGap is running fullscreen (using a Fullscreen Theme).

To be honest, I *have* seen this work in an older project so it must be something that was introduced to Android after my last viewing of it.

In any event the community at large has provided a fix – after some Googling I came across this StackOverflow post:


The above gives enough directions to get started though some small points are left out. The missing step-by-step is why I’m posting today – I’m going to walk through the entire process and to touch briefly on the variant of the fix also posted in the above link.


The “AndroidBug5497Workaround” & “AdjustInputHeight” Java Classes

“AndroidBug5497Workaround” is the name of the class that defines the first fix. It works as advertised and in fact performs better than the variation of it on my Samsung Galaxy S2 (Android 4.1.2). This fix will bump up the display immediately with no delay or animation. The view stays shifted upwards revealing the element with focus until the keyboard is put away where the view then returns to normal.

The second example, a variation of the first, animates the view up but has a bug that shifts the view down to its default position after the first keystroke. Thereafter, it works fine. Again, I found the first example to be more reliable and in fact preferable to animating the view.

If you’re curious you can implement the second one and play with the animation time setting – look for the number “500” in the source. I assume it represents milliseconds.

How To Implement

Navigate to the root of your project

Locate your “src” folder. In a PhoneGap 3 Project it would be here (substitute the bracketed text for your own project-specific values):

  • projects\[APP NAME]\platforms\android\src\com\[NAMESPACE]\[APP NAME]

Or in Eclipse you might find the “src” folder in the Package Explorer.

Once you locate your “src” folder you should be looking at your main activity java file – we’ll be giving it a friend…

Create a new text file to hold the fix

Create a new text file. Then, go to the link given above and copy the source for the first AndroidBug5497Workaround example and paste it into your new text file – save and close.

Rename the file

Next, rename the file so that it matches the class that it holds and give it the java extension. It should look like this:

  • AndroidBug5497Workaround.java
Open your Main Activity

With a text editor open your main activity Java file – it was the first file you saw in your “src” folder and probably is named after the name of your app. Look at the top of the file – you are looking for line a that looks like this:

  • package com.[NAMESPACE].[APP Name];

Its the only line that starts with the word “package” – copy that entire line and paste it at the very top of the other file – the one you’ve just created.

Add the fix to your main activity

Go back to your main activity Java file – you will need to paste this line after the super.loadUrl line:

  • AndroidBug5497Workaround.assistActivity(this);

It should look like this when you’re done:


Thats it – If in Eclipse clean your project and try it.

If you want to try the other example (again at the StackOverflow link given at the top of this page) then just follow the same procedure but be sure to use its class name (AdjustInputHeight) as the name of the file and when adding to your main activity.

Speeding Up the Android Emulator with HAXM

27 Aug 2013

The typical experience with the Android Emulator on Windows is that it is essentially unusable. But if you throw hardware acceleration into the mix then it becomes possible to get the emulator working quite well – well enough for everyday use.

The cause of the emulator’s lack of performance is due to it being implemented completely in software. However, Intel has a set of hardware accelerator drivers called HAXM for computer’s utilizing it’s chips. The caveat is that your Intel processor has to support Intel’s Virtualization Technology (VT) in order for the drivers to work. See this link – Microsoft® Hardware-Assisted Virtualization Detection Tool – to see if your system supports Intel’s VT.

Install HAXM

You can install HAXM through the Android SDK Manager (Within Eclipse, go to Window > Android SDK Manager and look for “Intel® Hardware Accelerated Execution Manager” under the Extras folder and install it) or via a separate download/install file. The following link describes both: Installation Instructions for Intel® Hardware Accelerated Execution Manager – Microsoft Windows*.

[EDIT 10/23/13] I recently bought a new laptop and proceeded to setup my android dev environment and had gotten to the point of installing HAXM. I went to the SDK Manager and selected HAXM from the bottom of the list and downloaded it. The SDK Manager indicated that HAXM was installed but it in fact was not – it was merely downloaded but not installed. I had to find where the installer was downloaded and install it manually. The file is downloaded to your “extras” folder which is somewhere within your Eclipse installation directory. I navigated to my Eclipse install folder and did a search for “extras” and quickly found the file. Here’s a screen cap:


You can see that the file you want to execute is IntelHaxm.exe.

I was then presented with this message during the HAXM install:


When I clicked the OK button the install failed – the Intel VT must be enabled first before you can install HAXM.

While researching how to do this I came across a blog post that said some people’s Windows 8 machines would no longer detect USB devices after enableing VT. The fix that worked for that particular blogger (and others) was to disable fast boot. Not wanting to fall victim to this bug I went ahead and disabled that feature. If you are in Windows 8 and would like to do the same you can do so in Control Panel, under Power Settings, select the option of choosing what the power button does. Disable the “Fast Startup” option.

Anyway so now I have to enable VT which by the sound of it means that I have to boot into my system’s BIOS. You will have to search on how to do this for your particular machine, but for my Lenovo IdeaPad Y410p i just had to hold down the F2 button during bootup. Once I enabled VT in the bios and rebooted I was able to complete the HAXM install.



Create a HAXM-enabled AVD

Once HAXM is installed you’ll want to create a HAXM-enabled AVD, here’s the walk-through on how to do so.

Start Eclipse and select Window > Android Virtual Device Manager.


The AVD Manager appears.


Click “New” to create a new Virtual Device.


The “New AVD” window is where you setup the AVD and specify that you want to use HAXM. Note that HAXM is only available for Android 4 and higher. If you set your Android Target to anything below then HAXM will not be available to you.

The first thing to do is to give your AVD a name. As this will be a HAXM accelerated AVD I personally like to use “HAXM” as part of the name. In this case I’ll call the project “my_tablet_HAXM” (note that spaces are not permitted thus the underscore characters in the name).

Next click the Device list and choose “10.1” WXGA (Tablet)”. Immediately you will notice that many of the other fields have been filled in for you, as seen below:


To use HAXM you must change the “CPU/ABI” field to “Intel Atom (x86)” however you will see that the “CPU/ABI” field is greyed out. HAXM is only available on API level 15 (Android 4.0.3) and higher. Ours is currently set for something much lower so lets bump up the “Target” to 17 (Android 4.2). Now you can change the CPU value to x86.

If however you see the text “No system images installed for this target” in the “CPU/ABI” field you need to go to your Android SDK Manager and install the x86 images for the version of android you’re attempting to use. Once you do that then return to this step and you’ll be able to select “Intel Atom (x86)”.


In memory options you can go as high as 1024MB of RAM. I’ve left it as is – half of that at 512 – feel free to go to 1024 but don’t exceed that number as you wont see any benefit.

In the “SD Card” section you will want to give your AVD some memory to store whatever it is your app might be doing – the default seems to be 9mb (if you don’t enter a value). I’m going to enter an arbitrary value of 16MB.

Next at the bottom are 2 options – “Snapshot” and “Use Host GPU”.

“Snapshot” retains the state of your application so that programs installed in one session carry over to the next thus behaving just like a real device. Otherwise whatever you install/configure will be cleared when you shut down the emulator.

“Use Host GPU” is the switch that enables hardware acceleration and utilizes the GPU to speed up screen rendering for Android 4.0.3 (API Level 15, revision 3) or higher. We’re using a target level of 17 so we meet that requirement. Note that as of API Level 17 GPU acceleration is experimental so if you encounter some oddness (i.e., screen flickering) its most likely due to your enabling HAXM for your AVD.

I’ve read that both Snapshot and the GPU can conflict in some way – regardless you likely want both. In this case I’ll forgo the use of Snapshot. Your new AVD should look like this:


Click “Ok” and your new AVD is added to the AVD Manager. You now have this AVD available to you whenever you want to test your apps. If you like you can kick the tires to see how it performs by selecting the new AVD from the list and clicking the “Start” button.


You’ll have some Launch Options appear, go ahead and skip the options by clicking the “Launch” button.

The Emulator starts…


From here go ahead and play with things – there’s a marked improvement in performance.

Prevent Screen Rotation in PhoneGap / Android

21 Jun 2013

You may have an app at some point that requires a set screen orientation. Using PhoneGap in Android this is done by editing your project’s manifest.xml. This file is located in your project root. Double click the file to open it within Eclipse and note the activity node:

<activity android:configChanges="orientation|keyboardHidden"
    android:label="@string/app_name" > 

You will add the following to it:




Which would look like this:

<activity android:configChanges="orientation|keyboardHidden"
    android:screenOrientation="portrait" > 

In PhoneGap 2.8.1 they have added a “preference” to config.xml for screen orientation, but oddly it doesn’t seem to work on the Android 4.1.1 test device I have (a Samsung Galaxy Tab 2).

The tag looks like this:

<preference name="orientation" value="portrait" />

Simply add it above the feature tags in config.xml… but as I mentioned, it doesn’t work. Maybe this is forward looking or maybe its broken in PhoneGap 2.8.1, either way the first method continues to work.

Off-Market Android Installation Instructions

20 Sep 2012

I keep having people asking me how to do this. This is certainly covered exhaustively on the Internet here and there… but here’s yet another step-by-step on how to install Android Apps (APK’s) outside of a marketplace such as Google Play or GetJar. Note that it usually not a good idea to install non-market apps but in some cases its necessary, such when sending a demo build to a client, etc:

How To Install an APK onto an Android Device


By default all Android devices will only install applications from Google Play. To install an APK outside of Google Play you must enable the ability on the device.

  1. Settings
  2. Security
  3. Unknown Sources – Allow installation of non-market apps <<< make sure
    this checkbox is checked as illustrated in the image below


There are a couple of ways to do this:

  1. Download from a website
  2. Plug your phone into your computer and then copy the APK from your computer to your device


Download a File Manager so that you can browse your file system to locate and install the APK. There are two good free file managers in the Google Play market, one is “Astro” and the other is “ES File Explorer”, I prefer the later.

  1. Launch the Play Store
  2. Search for “ES File Explorer”
  3. Install the app

  1. Launch the app – by default ES File Explorer starts out showing files in the root of your SD Card (on my Galaxy S2 this is the case)
  2. Locate the file that you downloaded/copied to your device
    • If you downloaded the APK, it is likely in your “download” folder. Scroll down and locate “download”, and open the folder
    • If you downloaded the APK, it might also be in your external sd “download” folder. Scroll down and locate and tap “external_sd”, then tap the “download” folder that may be in that location
    • If you copied the APK from your computer to your device then you likely copied it to the external sdcard on the device. In this case scroll down and tap “external_sd” or similar. Locate your APK. Note that folders are displayed first, files second, so if you dropped the APK into the root of the external sd then it’s at the bottom of the list, just scroll down. If you created a folder for the APK then naturally you will need to locate and open that folder


Once you locate the APK simply tap it and install.


All content © 2012-2017.