Category Archives: Eclipse

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:

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.

ADB Server is Out of Date – Eclipse Error

04 Mar 2013

This morning I was unable to install/launch an android app from Eclipse to my test android tablet. I suspected it may have something to do with my having rooted an Android tablet the previous working day – but I can’t find a causal link to that effect.

Anyway, I either repaired the issue or found a work-around – either way I’m up again. Time will tell if this has been resolved… so here’s what I did:

  • I discovered online that HTC-Sync seems to cause this, and I *do* have an HTC EVO 4G test phone so I opened Task manager and killed the HTC Sync process (To be honest, this has never been an issue previously. I suspect that this step was unnecessary.)
  • Next I ran adb kill-server via the command prompt
  • I then restarted the server by issuing adb start-server
  • Eclipse didn’t like the above two steps so I restarted Eclipse
  • … and things seem to be ok atm
  • I’ll update this post if this continues to happen, else if this is the last sentence here then the problem for me has disappeared…

Javascript Validation Errors in Eclipse

12 Jan 2013

Every once in a while I’ll run into a JavaScript validation error – Eclipse’s JavaScript validator will sometimes catch something that I’ve missed and will print out a line number and file name in the Eclipse Problems View. The error I got today was a JavaScript validation error on line 1 of my phonegap javascript file. Line 1 contains a comment. Ooookay…

Disabling Javascript validation had not effect, cleaning the project did nothing. Restarting Eclipse and the resort of all last resorts (besides starting a new project from scratch and having to reinstall all plugins and custom work) I even restarted my computer.

The solution I found was to physically remove the phonegap js file from the project directory, right click the project root in the File Explorer and hit F5 or right-click and choose “Refresh”. The error should disappear. Add the js back to where it was and refresh the Project Explorer again. Problem solved, my app is now running!

Losing Device Connection in Eclipse

20 Jun 2012

There may come a time where you will encounter an “AdbCommandRejectedException error: device not found” while trying to upload your app to your device from within Eclipse. This message will appear in the console and will be accompanied by this text: “Error during Sync: An established connection was aborted by the software in your host machine”. As a result you will be unable to install your app. Opening DDMS will show that the device is not connected to your computer a it simply doesn’t appear in the device list even though the phone is in fact physically connected.

To further illustrate:

To resolve this without restarting Eclipse you can execute a BAT file that will restart the ADB server. To do this navigate to your Android installation folder and locate the “platform-tools” folder. Within that folder create an appropriately named BAT file, for example, “restart-adb.bat”. Edit the newly created file in a text editor such as Notepad and add the following two lines:

adb kill-server && adb start-server

Save and close. TO restart ADB simply double-click your bat file and the server will be restarted. A command prompt will appear informing you of what is happening:

Thats it, the ADB has been restarted.

Solving “The connection to the server was unsuccessful” Error in Android/PhoneGap

10 Apr 2012

At some point in time you will always have to update your dev environment – and inevitably when doing so you will find that you can’t compile your apps any more for any sort of a number of reasons – doesn’t matter if its iOS or Android (though I find its much, much more common on iOS). Well, today I’ve updated my Android SDK since I’d like for the first time ever to be able to use the AVD as Google has improved performance in that area. However, upon compiling one of my apps I have run into this error:

04-10 10:46:13.672: I/System.out(4057): onReceivedError: Error code=-6 Description=The connection to the server was unsuccessful. URL=file:///android_asset/www/index.html

This can be solved by adding a line to your main file:

super.setIntegerProperty("loadUrlTimeoutValue", 7000);

The timeout value itself is arbitrary, here I have it at 7 seconds. Adding this one line above the super.loadUrl resolves the “Connection to the server was unsuccessful” error.

Also, check to make sure that any remote scripts such as those being delivered to the app from a server are accessible. Sometimes I forget to remove the remote debugger from a project and find that this error will appear because the script cannot be downloaded – in that case you see the error message appear while the app loads behind it. So, check your script tags for remotely loading scripts and remove any hooks to remote debuggers/testing servers. You should also download copies of javascript libraries and keep them within your app to remove or at least reduce the chances of this error appearing.


All content © 2012-2017.