the wikipedia article points out that the RFC952 forbids trailing hypens in domain names. Androids browser/webview enforce this, most other browsers (and heck DNS servers do not seem to bother)
The source code for the Apache HttpCore lib is not in the Androd SDK source package, so you need to get it direct from the AOSP git repo.
Sunday, September 30, 2012
Tuesday, August 28, 2012
Java Network Timeout handling
So this blog post (via stackoverflow as usual) points out that you need to manually handle timing out reads when using URLConnection and hence also HttpURLConnection.
The post also helpfully provides example code for such a manual timer:
The post also helpfully provides example code for such a manual timer:
try { URLConnection con = urlObj.openConnection(); con.setConnectTimeout(5000); con.setReadTimeout(5000); new Thread(new InterruptThread(Thread.currentThread(), con)).start(); retVal = new Source(con); } catch (IOException e) { System.err.println("aborted parsing due to I/O: " + e.getMessage()); throw new IndexingException("aborted parsing due to timeout - " + aUrl); } public class InterruptThread implements Runnable { Thread parent; URLConnection con; public InterruptThread(Thread parent, URLConnection con) { this.parent = parent; this.con = con; } public void run() { try { Thread.sleep(5000); } catch (InterruptedException e) { } System.out.println("Timer thread forcing parent to quit connection"); ((HttpURLConnection)con).disconnect(); System.out.println("Timer thread closed connection held by parent, exiting"); } }
Monday, August 13, 2012
latest android sdk bug plus httpd
emulator in r20 segfaulting on a headless box without opengl.
the simple node based http static server to use:
https://github.com/nodeapps/http-server
to not have to use sudo anymore (on my laptop) to install node modules via npm globally (-g flag):
sudo chown -R username:group /usr/local/bin/
sudo chown -R username:group /usr/local/lib/
Monday, July 9, 2012
Android Http NPEs
Lovely...
Search google for a NPE from Androids Http package:
libcore.net.http.HttpConnection$Address.hashCode NPE
leads to bug report, which leads to another which finally points me to looking at my url closely and realising I typoed the protocol scheme. As the comment I left suggests, life would have been much clearer with a slightly more specific exception the a null pointer. Sigh.
Search google for a NPE from Androids Http package:
libcore.net.http.HttpConnection$Address.hashCode NPE
leads to bug report, which leads to another which finally points me to looking at my url closely and realising I typoed the protocol scheme. As the comment I left suggests, life would have been much clearer with a slightly more specific exception the a null pointer. Sigh.
Sunday, July 1, 2012
Android Emulator keyboard
Well this was a little time waster today:
Turns out that Android SDK r20 now defaults the hw.keyboard property to no.
This means that you will all of a sudden find that after upgrading to r20, keyboard entry (both physical and onscreen) will stop working in both existing and new AVDs.
So you need to set the property explicitly in each AVD config via the GUI or in:
.android/avd/MY_AVD_NAME.avd/config.ini
Turns out that Android SDK r20 now defaults the hw.keyboard property to no.
This means that you will all of a sudden find that after upgrading to r20, keyboard entry (both physical and onscreen) will stop working in both existing and new AVDs.
So you need to set the property explicitly in each AVD config via the GUI or in:
.android/avd/MY_AVD_NAME.avd/config.ini
Thursday, June 21, 2012
More Bash magic
set to automatically cd into a dir by typing its name:
shopt -s autocd
go back to previous pwd ($OLDPWD):
cd -
rename a path with a new suffix:
mv /var/www/test{,1}
Again all courtesy of my co-worker Ben.M
Tuesday, June 19, 2012
Android SDK Ant bugs
BEWARE: if you are using r15 of the Android SDK and building with a custom Ant post-build target then this bug might bite you! r17 through to r19 is confirmed as working ok.
Monday, June 11, 2012
Ubuntu UI Annoyances
If you find ubuntu new "on hover" osx-envy scrollbars as frustrating and annoying as I do you want to do:
sudo apt-get remove liboverlay-scrollbar*
(thanks to co-worker Ben M. for this super handy tip).
sudo apt-get remove liboverlay-scrollbar*
(thanks to co-worker Ben M. for this super handy tip).
Wednesday, May 23, 2012
Sunday, May 20, 2012
Git and Vim
Must remember to do to set the EDITOR shell env var to get nice git commit mesg highlighting everytime I do a OS re-install.
Tuesday, May 1, 2012
On Android Services, Threads and Exceptions
So it turns out that if you actually read the developer documentation carefully, "Services" in Android are not "background jobs" or "daemons" as you might expect from the name. No what they are is in fact simply a configuration mechanism to inform the Android OS that your application has work to do that can occur at times when your application Activities are not visible to the user.
Thus Services not only do not have their own separate Thread, but in fact are simply executed by your applications main thread, in response to events based on the service life-cycle. An important result of this is that within a Service or an Activity, all long-running jobs should be performed on a separate background as otherwise they will be run on the main thread.
The main source of confusion comes about because the Android developer documentation talks about Services being "killed" and restarted by the OS. But this actually simply referring to the process (i.e. the Linux process) which hosts each apps Dalvik VM and the fact that the OS can kill the process at anytime such as when memory is low. It's only in this case that Services would be "restarted" by the OS/Framework, but this of course only refers to the Services lifecycle callback methods (e.g. onCreate and onStartCommand) being called by your apps main thread after your app is restarted inside a new VM running within a new process. Once you understand this, the purpose of the "STICKY" flags then becomes obvious, as just being means to inform the framework how it should go about re-calling those callback methods after an app is restarted in a new VM.
An interesting result of all this is that there is no such thing as a Service "dying" in your app, except of course for the case of it throwing an uncaught exception, which would cause your apps main thread to exit and thus your whole app to "quit" bringing up the famous "Force Close" system dialog. Should you wish however to handle that situation, you have available to you the Thread.setDefaultUncaughtExceptionHandler() method which will allow you to catch unhandled exceptions and doing something useful (like logging them to the device storage or some external service) prior to your current foreground Activity existing.
Thus Services not only do not have their own separate Thread, but in fact are simply executed by your applications main thread, in response to events based on the service life-cycle. An important result of this is that within a Service or an Activity, all long-running jobs should be performed on a separate background as otherwise they will be run on the main thread.
The main source of confusion comes about because the Android developer documentation talks about Services being "killed" and restarted by the OS. But this actually simply referring to the process (i.e. the Linux process) which hosts each apps Dalvik VM and the fact that the OS can kill the process at anytime such as when memory is low. It's only in this case that Services would be "restarted" by the OS/Framework, but this of course only refers to the Services lifecycle callback methods (e.g. onCreate and onStartCommand) being called by your apps main thread after your app is restarted inside a new VM running within a new process. Once you understand this, the purpose of the "STICKY" flags then becomes obvious, as just being means to inform the framework how it should go about re-calling those callback methods after an app is restarted in a new VM.
An interesting result of all this is that there is no such thing as a Service "dying" in your app, except of course for the case of it throwing an uncaught exception, which would cause your apps main thread to exit and thus your whole app to "quit" bringing up the famous "Force Close" system dialog. Should you wish however to handle that situation, you have available to you the Thread.setDefaultUncaughtExceptionHandler() method which will allow you to catch unhandled exceptions and doing something useful (like logging them to the device storage or some external service) prior to your current foreground Activity existing.
Sunday, April 15, 2012
Automatic Android Release Builds with CI
So if you are using a CI server (eg. Hudson aka Jenkins) to build your Android app, when you come to release it you'll want to do that automatically too.
All thats required is this kind of stanza in your build.xml:
<property environment="env"/>
<target name="-post-build" >
<copy todir="bin">
<fileset dir="bin">
<include name="myappname-*.apk"/>
</fileset>
<globmapper from="myappname-*.apk" to="myappname-*.${env.BUILD_NUMBER}.apk"/>
</copy>
</target>
As you can see I'm also naming the final apk file with the Jenkins build number environment variable. There are a lot more other env vars that Jenkins sets that you can use.
Also note the reason I've used the globmapper is that this will work for both the debug and release build targets that are pre-defined in the standard android project ant build configs. This means you can have Hudson build configs for both debug and release.
If you want your release apk to be properly signed, you need to create a certificate and then point your ant build at it (ant.properties):
key.store=path/to/my.keystore
key.alias=mykeystore
If you don't want to type in the password for each build, you can add the following to your local.properties:
key.store.password=secretpasswd
key.alias.password=secretpasswd
And also add the passwd properties to your Jenkins config (click "Advanced" button in the "Invoke Ant" section of your build config). This way you never have to check your keystore passwords into version control.
Oh as a bonus, if you want to be able to access the build information within your apps code at runtime, you can stash this in a string value by putting something
like this in your build.xml:
<property environment="env"/>
All thats required is this kind of stanza in your build.xml:
<property environment="env"/>
<target name="-post-build" >
<copy todir="bin">
<fileset dir="bin">
<include name="myappname-*.apk"/>
</fileset>
<globmapper from="myappname-*.apk" to="myappname-*.${env.BUILD_NUMBER}.apk"/>
</copy>
</target>
As you can see I'm also naming the final apk file with the Jenkins build number environment variable. There are a lot more other env vars that Jenkins sets that you can use.
Also note the reason I've used the globmapper is that this will work for both the debug and release build targets that are pre-defined in the standard android project ant build configs. This means you can have Hudson build configs for both debug and release.
If you want your release apk to be properly signed, you need to create a certificate and then point your ant build at it (ant.properties):
key.store=path/to/my.keystore
key.alias=mykeystore
If you don't want to type in the password for each build, you can add the following to your local.properties:
key.store.password=secretpasswd
key.alias.password=secretpasswd
And also add the passwd properties to your Jenkins config (click "Advanced" button in the "Invoke Ant" section of your build config). This way you never have to check your keystore passwords into version control.
Oh as a bonus, if you want to be able to access the build information within your apps code at runtime, you can stash this in a string value by putting something
like this in your build.xml:
<property environment="env"/>
<target name="-pre-build">
<echo file="res/values/buildtag.xml"><![CDATA[<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="build_version">ABCXYZ123</string>
</resources>
]]>
</echo>
<replace file="res/values/buildtag.xml" token="ABCXYZ123" value="${env.BUILD_TAG}"/>
</target><echo file="res/values/buildtag.xml"><![CDATA[<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="build_version">ABCXYZ123</string>
</resources>
]]>
</echo>
<replace file="res/values/buildtag.xml" token="ABCXYZ123" value="${env.BUILD_TAG}"/>
Panel indicators for Unity
If you just want the system load indicator panel applet back just use this.
A whole lot more applets are listed in this answer.
A whole lot more applets are listed in this answer.
Tuesday, April 10, 2012
Html Notifications
Chrome has a simple API spec for doing "desktop notifications" from webpages. There's even a quasi-standard "editors draft" at the W3C for it.
Luckily someone has been nice enough to write a Firefox add-on to implement the API in Firefox (open source).
Unfortunately some sites such as Flowdock only sniff for the presence of the API in the DOM instead of actually doing a call to the API to ask user permission as suggested by the spec itself and so fails due to the different approach taken by the add0on vs the implementation in Chrome.
Luckily this is easily fixed by pre-approving Flowdocks url via a property in about:config
Luckily someone has been nice enough to write a Firefox add-on to implement the API in Firefox (open source).
Unfortunately some sites such as Flowdock only sniff for the presence of the API in the DOM instead of actually doing a call to the API to ask user permission as suggested by the spec itself and so fails due to the different approach taken by the add0on vs the implementation in Chrome.
Luckily this is easily fixed by pre-approving Flowdocks url via a property in about:config
key: extensions.html5notifications.permissions
value: {"www.210computing.com":0, "mydomain.flowdock.com" : 0}
Monday, April 9, 2012
Pretty JSON and Dark Ubuntu
Do get Eclipse using a dark theme to match dark background syntax highlighting plugin you need to set the gtk theme using myunity (from this answer on SO).
Pretty printing JSON with bash using just Python:
Using NodeJS and the pretty-data module to make a simple shell script.
Pretty printing JSON with bash using just Python:
Pretty JSON using an add-on in Firefox.echo '{"foo": "lorem", "bar": "ipsum"}' | python -mjson.tool
Using NodeJS and the pretty-data module to make a simple shell script.
Sunday, April 8, 2012
Mp3s
So out of box install of Ubuntu 12.04 now includes mp3 encoding (as well as decoding using fluendo decoder).
But theres this issue with VBR encoding (which is set in default gstreamer pipeline for mp3 encoding). And yes its been open just over 6 years!
Still I learnt about a handy tool called "mp3check" (and id3v2), exactly the kind of toold I'd been looking after for ages.
Of course the correct solution is to use a decent cdripper like the cli-based abcde.
But theres this issue with VBR encoding (which is set in default gstreamer pipeline for mp3 encoding). And yes its been open just over 6 years!
Still I learnt about a handy tool called "mp3check" (and id3v2), exactly the kind of toold I'd been looking after for ages.
Of course the correct solution is to use a decent cdripper like the cli-based abcde.
Saturday, April 7, 2012
Getting Android Emulator accelerated
On Ubuntu 10.04 or later install KVM as follows:
- sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
- install 2.3.3 Intel Atom Image via Android SDK Manager
- run: emulator-x86 -avd <avd_name> -nosound -qemu -m 1024 -enable-kvm
Tuesday, March 13, 2012
Plain Text Please
Can't believe I only noticed this feature in Chrome this morning to paste plain text into any input field.
Firefox has the functionality in a add-on.
Firefox has the functionality in a add-on.
Tuesday, February 14, 2012
Countdown and android.os.*
So I needed a countdown timer for an Android project I'm working on and after building a simple one myself, a came across android.os.CountDownTimer - who knew android shipped with one!
That got me interested in having a browse through andriod.os.* package to see what else the Android devs had squirreled away in there...
Turns out a whole bunch of handy stuff! Like:
That got me interested in having a browse through andriod.os.* package to see what else the Android devs had squirreled away in there...
Turns out a whole bunch of handy stuff! Like:
- An simple API inotify
- PowerManager
- Filesystem stats
- a persistent, system-wide, blob-oriented "logcat"
- the very handy AysncTask
Thursday, January 26, 2012
Easy search of Stackoverflow in Chrome (and Firefox)
To easily search opensearch enabled sites (like StackOverflow) in Chrome, just start typing the name of the site in Chromes address bar, when the site name is matched, press TAB, it will then convert into a site search for that site and you can then keep typing in your search query.
To do something simliar with Firefox "awesome bar" using a feature called "Add a keyword for this search" its a slightly different procedure. Thought the nice thing with firefoxes method is it works with any search input field and not just opensearch enabled sites.
And don't forget that if you want to access your local dev machine from an app running in the emulator, you need to use 10.0.2.2.
To do something simliar with Firefox "awesome bar" using a feature called "Add a keyword for this search" its a slightly different procedure. Thought the nice thing with firefoxes method is it works with any search input field and not just opensearch enabled sites.
And don't forget that if you want to access your local dev machine from an app running in the emulator, you need to use 10.0.2.2.
Thursday, January 12, 2012
Android testing with ant
When running android tests using ant, you can specify a specific device to run the tests on when you have more than 1 device available to adb on your system. The property is: adb.device.arg so you can do:
ant -Dadb.device.arg="-s emulator-5554"
Or even better use a script like this gist.
ant -Dadb.device.arg="-s emulator-5554"
Or even better use a script like this gist.
Monday, January 9, 2012
Jenkins, adb, ant, oh my!
So this bug, who's root cause is this bug (yes reported in Jul '09 and still not fixed!), means that if you want to have a unit test failure cause your whole Ant build to fail and thus show up on your Jenkins/Hudson CI server, you need to do put this macro override into your build.xml.
Subscribe to:
Posts (Atom)