Posts

Showing posts from 2012

How to bypass SSL certificate checking in Apache Cordova 2.2 on Android

How to bypass SSL certificate checking in Apache Cordova 2.2 on Android (or how to override CordovaWebViewClient in versions of Cordova 1.9+) I came across a strange issue where I was unable to access a secure URL using HTTPS.  At first I thought it was due to the Cordova whitelist since there was an issue with it in Cordova 2.1.  In order to access an external URL you have to whitelist them eg <access origin="https://www.wikipedia.org" subdomains="true"/> This didn't help though and even if I allowed all URLS using <access origin = "*"/> it still didn't work.  Strangely though it was only one secure URL I couldn't access, not all of them As it turns out, it was probably to do with the way Cordova assesses valid certificates.  When an Android app is signed and deployed it is deployed in 'production mode' which means that any secure URL accessed must have a valid certificate signed by a certificate authority (C

Creating an Android Jelly Bean Daydream from a WebView

Image
One of the new nifty features on Android Jelly Bean 4.2 is the concept of daydreams (basically a screensaver but also displays when docked etc).  I wanted to create one that displayed an HTML page, which makes for prety easy development and this is how First of all, this assumes you have API 17 (Android 4.2) installed, otherwise you won't have access to the relevant Android class Android Daydream option You need to create a new class that extends android.service.dreams.DreamService and override the onAttachedToWindow() method which is what is called when the service starts up.  In here all you really need to do is create a new WebView as normal and attach it.  Example code below import android.annotation.TargetApi; import android.service.dreams.DreamService; import android.webkit.WebView; @TargetApi(17) public class MyDreamService extends DreamService {   @Override   public void onAttachedToWindow() {     super.onAttachedToWindow();     // Allow user touch     setInt

Eclipse Appcache Generator - auto-generate HTML5 appcache files

HTML5 Appache I won't go into a full explanation here (if you want a tutorial the  HTML5 Rocks  website) but HTML5 appache is a method of caching web content so that, when offline, it can still be accessed One method of doing this is to add a meta tag to each page specifying an appcache file, which will tell the browser to cache that page. But what if you want to tell the browser to cache everything when the site is first accessed? Well HTML5 has a way of doing that too - you still add the meta tag but also specify the files to be cached in the file. When it is accessed, those files will be cached. This though leaves you with a problem - how do you make sure you locate every file to be cached and add them to the file? This is where this plugin can help Plugin The Appcache Eclipse Plugin is a plugin for the Eclipse IDE that will check all your files for your site and add all html, image, css and javascript files to the appcache. Once the plugin is installed, all you need t

Running Jenkins CI on a Raspberry Pi

Image
I've had this idea for some time of running my own Jenkins CI (continuous integration) server for building my mobile apps.  That was exactly what I intended to run on my Raspberry Pi when it arrived.  Now it has arrived, I thought I would share an issue I had so that others with the same problem can also solve it My Raspberry Pi My Pi is running Raspbian, which is Debian based, so theoretically installing Jenkins is as simple as running apt-get: sudo apt-get install jenkins This certainly installed it ok, but for some reason, it wouldn't start up.  Searching google revealed on possible issue regarding Java versions - specifically that Sun Java currently doesn't run on the Raspberry Pi.  A summary of how to fix that issue is: sudo update-alternatives --config java then chose OpenJDK followed by a reboot of the Pi.Jenkins starts up as expected after boot. However, my installation had already installed OpenJDK, so that wasn't my issue As it turns out, t

No cursor in Ubuntu linux 11.10

I've had this weird problem lately on Ubuntu 11.10 (64 bit) - I only seem to have a cursor in some windows and never in any of the system windows (desktop, unity bar etc). Well today it was winding me up so I decided to try and fix it A quick google got me this page: No Cursor in Ubuntu 11.04 with a Legacy Nvidia Card . Not the right version of Ubuntu I know, and I have no idea what video card I have either, as the system info shows it as 'unknown'. But I figured I'd try it anyway Steps from that page: 1. Open a terminal window 2. Stop the x server: sudo service gdm stop 3 Uninstall the nouveau driver: sudo apt-get --purge remove xserver-xorg-video-nouveau 4. Reboot the machine When I got the step 2 though, it said the gdm service wasn't found, so I just did step 3. This unfortunately stopped the cursor moving at all! So I reinstalled the nouveau driver, and now it works! Now idea why! So for anyone who needs this, my steps were: 1. Open a terminal

Apache Cordova (PhoneGap) + processing.js

The problem I wanted to be able to create cross-platform mobile applications whilst not having to do it in Javascript.  I've never liked Javascript, I'm not really sure why, maybe I don't fully understand it. The solution I had a brainwave that I could create a functional Java application using Processing (that I have used a lot and, hopefully, will be contributing author to a book on the subject if it ever gets published), port it to processing.js and deploy that as an Apache Cordova ( PhoneGap ) based mobile application.  As a short explanation, Apache Cordova is a cross-platform framework for writing and deploying HTML5 apps to most mobile platforms.  Processing is a graphical Java-based library of which processing.js is the Javascript equivalent.  Using both processing.js and Cordova, I should be able to deploy a java-based application into a cross-platform framework and run it as javascript The code This is the easiest way to do it (there are other ways

PhoneGap + processing.js = big problems

This is less a 'code solution' than it is a code issue, in that I don't know how to fix it and abandoned the solution.  I will likely go back and attempt to resolve at some point, but for now I just want to tell you about what I'd wanted to create, what the issues were and how it caused my PhoneGap app to be labelled as "sucks!!!!" As I previously blogged this solution, I figured I should also share these issues The problem I wanted to be able to create cross-platform mobile applications whilst not having to do it in Javascript.  I've never liked Javascript, I'm not really sure why, maybe I don't fully understand it. The solution I had a brainwave that I could create a functional Java application using   Processing  (that I have used a lot and, hopefully, will be contributing author to a book on the subject if it ever gets published), port it to   processing.js   and deploy that as an Apache Cordova ( PhoneGap ) based mobile a

The PhoneGap Viewport size is too small on Android?

Image
I spent quite some time today trying to figure out why, when I load an external HTML file into my PhoneGap (Apache Cordova) app, the viewport only filled part of the screen Notice the big space at the bottom and the side border. I couldn't figure it out, so I started searching on Google: Googled solution 1 - Set the viewport meta tag Lots of the solutions I found involved setting the meta tag for the viewport, eg <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0/> However, this seemed to have absolutely no effect whatsoever.  I tried many variations of this Googled solution 2 - Set the page to use all the space Other solutions involved setting CSS so that the page filled the screen, eg html, body {   width: 100%;   height: 100%;   padding: 0;   margin: 0; } This also had absolutely no effect.  I was getting confused by now Googled solution 3 - Set Android properties I fo

How I brute-forced my own keystore password

How I brute-forced my own keystore password If, like me, you've been in the unfortunate siutation where you have forgotten your own keystore (or certificate key) password then help may be at hand. After some fruitless searching I decide to write my own piece of software to brute force my keystore certificate.  As I am/have been a Java programmer I decided to write it in the language I knew best, and this is how I did it. I have made the  source code  available for anyone who wants it Loading the keystore The Java API already has code for loading a keystore, java.security.KeyStore.  The keystore needs to be placed on the classpath (I just stuck it in the root on my Eclipse project) // Load the keystore in the user's home directory File file = new File(keystoreName); is = new FileInputStream(file); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); keystore.load(is, keystorePassword.toCharArray()); return keystore; The above code simply attempt

Installing and using mobilize.js to transform a desktop site to a mobile site

Image
Installing and using mobilize.js to transform a desktop site to a mobile site mobilize.js offers a neat and simple method of creating a mobile optimised website with very little change to the main desktop site. With a few lines of javascript and some css you can create a mobile optimised site without having to maintain 2 different sets of content. However the instructions on the official site aren't the best. So with some digging I managed to transform - From this (Firefox on my laptop): To this (Android browser on my Samsung Galaxy Nexus): with no html changes other than adding some <script> tags to the <head> element.  Plus automatic browser detection to display either site depending on the browser used - mobile, or desktop Here are some step-by-step instructions on getting it working. Why would you want to? So going back to the beginning, these were my requirements:  I wanted to create a mobile optimised site but, as I already had a

How to add AdWhirl to an Android app (part 2)

After my earlier post, I found another way of doing this which relies on setting the ad placement in a layout.  This also is pretty easy As I was getting poor results from AdMob I decided to add AddWhirl to my android app so I could use multiple ad providers.  Little did I know that the documentation for AdWhirl was going to be so bad!  A google search didn't help much, just lots of other people wanting to do the same and getting stuck or confused.  The official instructions didn't help much (https://www.adwhirl.com/doc/android/AdWhirlAndroidSDKSetup.html) - as soon as I had started I got a compile error because of something ommitted from the instructions. So I set out to solve the problem on my own. 1. Set your app up on your chosen Ad provider website (or multiple, but for this explanation I'll go with Admob).  You'll need the ID 2. Set your app up on the AdWhirl website.  Add the ad provider (in this case AdMob) and enter the ID.  Switch it on!  You'll ne

How to add AdWhirl to an Android app (with decent instructions!)

As I was getting poor results from AdMob I decided to add AddWhirl to my android app so I could use multiple ad providers.  Little did I know that the documentation for AdWhirl was going to be so bad! A google search didn't help much, just lots of other people wanting to do the same and getting stuck or confused.  The official instructions didn't help much ( https://www.adwhirl.com/doc/android/AdWhirlAndroidSDKSetup.html ) - as soon as I had started I got a compile error because of something ommitted from the instructions. So I set out to solve the problem on my own.  In the end the solution was pretty easy: 1. Set your app up on your chosen Ad provider website (or multiple, but for this explanation I'll go with Admob).  You'll need the ID 2. Set your app up on the AdWhirl website.  Add the ad provider (in this case AdMob) and enter the ID.  Switch it on!  You'll need the AdWhirl ID later, but not the AdMob one as AdWhirl handles that for you 3. Download t

Removing default apps from a rooted android phone

I recently needed to remove some of those rubbish default apps you get on android phones. You know the ones, the ones that come with the phone but you can't uninstall.  It is especially annoying if you don't ever want to use them and they are taking up loads of space on your phone because you have an Android version prior to Froyo (2.2) so apps can't be installed to the SD card One of my phones (a Sony Ericsson Xperia X8) is on Android 2.1 and I want it stay on that OS, but it was running out of memory.  I already rooted it some time back, and a quick google search came up with this great guide: http://androidadvices.com/remove-default-applications-rooted-android-phones/ I have one thing to add though, which is why I am writing this.  Once I'd uninstalled FourSquare, Facebook, Stopwatch, Planet3 and loads of other stuff I didn't want, I was surprised that they still showed as installed.  So I checked again with the article above, nope, definitely gone.  But they

Using RoboGuice with BlackBerry Android Runtime

I have recently been porting Android application to run on the new BlackBerry Tablet OS 2.0 which includes an Android 2.3 runtime.  However, one of my apps kept failing the BlackBerry packager checks because: 3 uses-package com.google.android.maps However my app wasn't using it, and a search of my code didn't reveal any uses of it either. It turns out that, because I was using RoboGuice, which has a MapActivity, the BlackBerry packager was picking that up, even though I wasn't using it. The only solution I could think of was to unpack the roboguice jar, delete the MapActivity class, then repackage it.  Then the BlackBerry packager was happy! Hope this helps someone