Posts

Showing posts with the label android

How to show Admob ads in an Apache Cordova app on Android

Since the demise of AdWhirl and my previous post about how to set up ads with Cordova, I've had to revisit it and get it working with AdMob which now uses Google Play Services.  Again there are very few instructions around for this, though I did find this useful looking Cordova plugin  which seems to offer a neat solution which is likely easier than the solution I'm about to propose and is cross-platform where I am only working with Android.  However, for various reasons, I don't want to use the Cordova tools, I want to do it manually.  If you're like me then here is how to do it This How-To uses a mash of the Cordova official documentation  on WebViews, my previous post on AdWhirl and the Admob Quick Start guide .  The premise here is that, since Cordova can be made to display in an Android WebView, and AdMob also uses WebViews, we can combine the two and display one in front of the other I'll assume you have an AdMob account and know how to create an...

Adding Multiple Google Accounts to Kindle Fire

Image
I recently bought a Kindle Fire because they are great value for an Android tablet and I knew they were ways of installing Google Play so I could access the apps I had already purchased through Google Play without having to repurchase them from Amazon. Specifically I wanted Minecraft for my son to play - honestly, for my son ;-) The Fire I bought was the 5th Gen Kindle Fire (not HD, I wanted inexpensive!) and the awesome instructions on How To Geek  worked perfectly at installing Google Play. I highly recommend this solution for installing it, it was simple to follow and easy to do. From here I was able to log in to Google Play and download my apps including Minecraft which I had previously paid for on another device If all you want from this is to install apps from Google Play using your account, you are all set! However, if, like me, you also want to add a second Google user (in my case, my son) so he can use his account to synchronise his games, I got a bit stuck.  Unli...

Manual upgrade of Apache Cordova for Android (2.9.0 to 3.7.0)

I hadn't upgraded Cordova for ages and was still on version 2.4.0 (now at 3.7.0 at the time of writing). so I was surprised, but mostly dismayed, that I now had to use the Cordova tools to create apps.  Maybe it is just me but I liked being able to copy the jar, javascript file and config into an Android app myself.  I did have a go at using the tool, but the npm still didn't create the jar I wanted and I'd be forever tied into using the tool.  So I spent some time working out how to upgrade manually, and this is how to do it.   This obviously relies on you having java and android installed, which I'd guess you have if you're upgrading an Android app Step 1 Download the latest zip file from  http://cordova.apache.org/  and unzip it. Step 2  Install android if necessary and add it to the OS path.  You need ANDROID_HOME set or the android executable on the path.  I added both. Make sure you have Android version 19 installed from Andr...

Android Daydream with Processing.js

Image
How to create an Android Daydream with processing.js I've spent some time working out how to get processing.js (a nice javascript graphics library ported from Processing ) to display an Android Daydream (basically a screensaver that activates when the device is docked or charging) I previously wrote about how to display an HTML page as a Daydream which forms the basis for this post.  Please see my earlier post for full details but to summarise you can load an HTML page in a webview like this webView.loadUrl("file:///android_asset/www/index.html"); Processing.js allows you to display Processing code as javascript in a page, so all you need to do is either embed the processing.js code or load the Processing PDE file containing the code as explained on the processing.js site I only had a couple of issues with it which were: 1. The js code seemed to run at a much  higher frame rate than my native Processing code such that my animation looked insane . In the end I...

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(); ...

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 propert...

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 sim...

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 ...

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 ...

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. ...

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