vrijdag 30 april 2010

Android Button with both text and an Image

So ImageButton lets you create a button with an Image. And Button has text... How to combine them?

On a regular Button you can add an image on top, left, right or bottom like this:

android:text="Some text here"

Using default Android Icons

The Android platform comes with a lot of default icons. Check this visual index of the android drawables to have an idea of what can be used.

Some examples of using these icons:

For use on an ImageButton, defined in xml:


Or the same set in code:

ImageButton btn = (ImageButton)findViewById(R.id.lock);

And another example of using these icons in your menu:

* Creates the menu items
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_HELP, 0, R.string.help).setIcon(
return true;

donderdag 15 april 2010

Automatic updates for Android apk files

Finally :D

The android market lacks some features. One of them is automated updates for the android applications you have installed. Now you have to check your downloads for any updates on the market and update them one by one...

As a programmer for android I also didn't find a way to display the comments on the apps I have deployed. Didn't really get into it but it seems that this appbrain has them all listed.

You can search the website for any apps you want and schedule them for installation on your device.

On your device you'll have to install this appbrain app from the market that will sync with your appbrain online account ;-). Get it here:

download android appbrain from android market

And you can read a review of the app here: http://www.androidtapp.com/appbrain-market-sync/

Working with images in Android

I'll try to explain some basic image functions for the Android platform. How to get images from the camera or the device I'll explain in another post. This is more about handling image files in code.

First of all you'll want to represent your image as a Bitmap. This way you can manipulate the pixels one by one. Use the BitmapFactory to create a Bitmap from several sources. Check the API for all the options. This example creates a bitmap from file:

File sdCard = Environment.getExternalStorageDirectory();
File imageFile = new File(sdCard, "image.jpg");
Bitmap image = BitmapFactory.decodeFile(imageFile);

A big concern when working with images is the available memory. For mobile Android devices this is very limited so watch out! You have some options to avoid the java.lang.OutOfMemoryError: bitmap size exceeds VM budget exception.

Don't really load the image when you only need to know the size of it. You can set BitmapFactory.Options to only load image boundaries like this:

BitmapFactory.Options options = new BitmapFactory.options();
BitmapFactory.decodeFile(imageFile, options);
int width = optins.outWidth;
int height = options.outHeight;

Sample the image if you only need to display

BitmapFactory.Options options = new BitmapFactory.options();
Bitmap bitmap = BitmapFactory.decodeFile(imageFile, options);

Recycle your bitmaps so garbage collector can come and get them

bitmap = null;

Remove callbacks when done displaying images with some Drawable object


dinsdag 6 april 2010

Installing Windows from bootable USB

I'm using an old Dell Inspiron 510m laptop with a broken (and therefore replaced by battery) optical drive. I could still access discs by using an optical driver shared from my network. But reinstalling Windows XP wasn't that easy! This is how I eventually got it working.

I tried this one (dutch version) before but got errors of a broken file. Probably something I did wrong myself. The guide that worked for me is found at http://www.911cd.net/forums//index.php?showtopic=22857.

1) copy all the contents of the source installation disc to a (non space) folder on your desktop. I'll reference it as C:\XPSOURCE from now.

2) plugin your USB drive. I used an old SanDisk Cruzer of 1GB. All contents will be lost so make a backup if needed.

3) download USB_MultiBoot_10.zip and unzip to run the USB_MultiBoot.cmd file in that directory. You can run it from the command line (Start > Run and enter to location of this file).

4) type "1" (without quotes) and hit enter, this will popup a utility to format your USB drive. Leave all options like they are and hit format.

5) back to the console you now type "1" followed by enter and give the path to the XP setup source files, for instance C:\XPSOURCE.

6) next type "2" and hit enter and provide the drivelleter of your USB-drive.

7) type "3" and hit enter and the bootable USB-drive will be created with the given sources.

When booting up your device from this disk you'll have to point it back to this drive each time you reboot until you've finished the installation of Windows. That is when you've successfully logged in. Only then you can start booting from the harddisk and remove the USB-drive.