I recently encountered this problem while trying to develop a WebView that is supported on Doughnut (1.6) and above. When presented with a https url the WebView just renders a blank page.

It seems that until Froyo, Android didn’t provide a public API to let you manually decide if you wanted to proceed to an untrusted web site via a WebView.

Note that in this case it is not even that the web site was untrusted (in the conventional sense) – it is because Thawte is not in the default list of trusted certificate authorities on Android. If you use the standard web browser on Android, the browser presents a typical warning dialog (as presented below) that enables you to accept the certificate and carry on.

Invalid certificate warning

If you are using Froyo as the target SDK then you can use:

engine = (WebView) findViewById(R.id.my_webview);
engine.setWebViewClient(new WebViewClient() {
 public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
 handler.proceed() ;

However, if you are not using Froyo then it seems you are out of luck. After some research, I concluded that I had the following options:

a) intercept all page requests and forward to external web browser if url begins with https (not a clean or nice user experience and totally unnecessary for Froyo and above)
b) add certificate of website to local keystore (in this case I am serving multiple web pages and the origin of many of these is not known until runtime)
c) make Froyo the minSDK and discard previous versions of Android (not a suitable option)
d) hack and use some private apis (the option described below)

To solve this problem we have to use a private interface (not published on SDK but present in real SDK runtime). As you can see in the Android src tree, the onReceivedSslError is indeed present (and used – it simply cancels the request) in Doughnut. However, this method is not presented to us in the SDK  – it is hidden because it contains a parameter type SslError which is located in a hidden package.  Therefore, we need to copy these src files into our project so that we can access them:

1) Copy WebViewClient.java into the package “android.webkit” within your src folder.
2) Copy SslError.java into the package “android.net.http” within your src folder.

Src files

3) Since we replicated the paths to the src files in the SDK, our code to override onSslError above now works on Android 1.6.

Caution: bear in mind that we are using a private API and Google reserve the right to change private APIs at any time – though in this case it is unlikely since they’ve now made this available in Froyo.

QR code for your business card

September 23, 2010

If you want to create a qr code that contains your contact details e.g. to include on your business card as shown in this video http://www.youtube.com/watch?v=3LkNlTNHZzE&feature=related&t=0m58s then you should head over to http://zxing.appspot.com/generator/

You’ll be able to create your own qr code (as shown below) for free. Below is a screenshot of my Android phone when I scanned the barcode.


android save contact screenshot

I use Windows for Android development because I find Eclipse too slow and clunky on the Mac especially on the MacBook Air. Recently I started using GIT for a project having used Subversion exclusively in the past. Given these constraints (Windows and Subversion experience) TortoiseGit seemed the obvious choice for me (I’m not trying to impress my friends with my command line skills any more!).

1) Download and install the lastest TortoiseGit MSI installer from http://code.google.com/p/tortoisegit/
Google code screenshot

2) Create your repository over at GitHub (Assuming you already have an account)
GitHub create repo screenshot

3) Initialise your project as a Git repository by right clicking on your project directory and selecting “Git Create repository here” from the context menu. A .git folder with all the necessary setup will be created within your project folder.
Init git repo on filesystem screenshot

4) Open your project folder and select the files and folders that you wish to include in your git repo (you will want to exclude the /bin and /gen folders for your Android projects). Then right click on these selected items and select “Git Commit -> master …” from the context menu.
commit files screenshot

5) A commit dialog will appear. Write your commit message and select the “select / deselect all” checkbox at the bottom to ensure that all your files are selected. Press OK. It is important to note at this stage your commit is being held locally on your PC as we have not yet linked our filesystem repo with github.com.
git commit msg screenshot

6) Before we can “push” our local commits (plural because you can make many commits locally before pushing them to the server) we must create an ssh key. The easiest way to do this is to open the Git Gui.  Right click on your project folder and select “Git Gui” from the context menu.
Open Git Gui screenshot

7) In Git Gui (notice our unstaged changes on the left), select Help –> Show SSH Key.  A dialogue will appear with your SSH key (if you have one). Most likely you do not have one yet so click the “Generate Key” button and enter a passphrase/password to secure your key when prompted. Your generated key will now appear in the textbox; copy it to the clipboard.
Create SSH Key Screenshot

8 ) Now you must add your ssh key to your github.com account.

a) Sign in to your account at github.com
b) Click the “Account Settings” link (top right of page)
c) Click the “SSH Public Keys” link (left middle of page)
d) Click the “Add another public key” link
e) Give your key a name e.g. github-<your_username> (you might have keys for other things!)
f) paste your key (that you copied to the clipboard in the previous step) into the textarea.
g) click add key
github.com ssh key setup

9) Now that you have created your ssh key and shared it with your github account, we are ready to push our commit (that we made in step 5) to our online github.com repo.  Right click on your project and select “Tortoise Git” –> “Push” from the context menu.
Push to Git screenshot

10) A dialog will appear asking where you would like to push the commit(s) to.  If you navigate to your project on github (e.g. http://github.com/damianflannery/MyProject for me) you will find an ssh url for your project (git@github.com:damianflannery/MyProject.git for my project). Copy your ssh url and paste it in the “Arbitrary URL” field of the dialog and click OK.  You will be asked to enter your passphrase/password for your ssh key and then all being well you will receive a success message.
Git Push Dialog Screenshot

That’s it! Head over to github.com to see your code.

Here is a handy static method to retrieve a thumbnail from a url and return a bitmap that can be used in your Android app e.g. assigned to an ImageView in your ListView or some other Layout.

public static Bitmap getBitmapFromURL(String src) {
    try {
        URL url = new URL(src);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        InputStream input = connection.getInputStream();
        Bitmap myBitmap = BitmapFactory.decodeStream(input);
        return myBitmap;
    } catch (IOException e) {
        return null;

1) Open up Window->Preferences->XML->XML Files->Editor

Eclipse Preferences Dialog

2) Check the “Split multiple attributes each on a new line” and adjust other options according to your liking (such as Indent using spaces and Indentation size)

3) Press OK to save the options

Now, all you have to do is press Ctrl-Shift-F or select Source->Format to produce a more readable and enjoyable programming experience like this:

Android XML file

I’ve finally found a solution to this really annoying problem!
  1. Run the SDK setup
  2. Wait for the error message
  3. Disable anti virus
  4. Install this unlocker program http://download.cnet.com/Unlocker/3000-2248_4-10493998.html
  5. Run the unlocker program
  6. select the tools directory to unlock it
  7. select yes in the installer.


This is a big deal for developers.

Device manufacturers such as Samsung and HTC like to add their own special sauce on top of Android to help differentiate themselves in the market. Unfortunately this means that they are somewhat slow to react when Google release a new code drop of the Android O/S.
Android Plaform Distribution

Android 1.5 12.0%
Android 1.6 17.5%
Android 2.1 41.7%
Android 2.2 28.7%

Data collected during two weeks ending on September 1, 2010

Other: 0.1% of devices running obsolete versions

These figures suggest that the device manufacturers now realise how important it is to provide a rapid upgrade path for their users when Google release feature packed updates like Froyo. This is important because when users can upgrade more quickly, fragmentation becomes less of an issue.