Thursday, November 5, 2009

DatePicker Widget

I've finally started working on my first app. I needed to use a DatePicker but didn't want to use a dialog, I wanted the DatePicker to appear on the current page. Here is my code:

* DatePickerActivity
public class DatePickerActivity extends Activity {

private DatePicker datePicker;

private int year;
private int month;
private int day;

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {

// Get access to Date Picker
datePicker = (DatePicker)findViewById(;

Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);

datePicker.init(year, month, day, dateSetListener);

* DatePicker.OnDateChangedListener
private DatePicker.OnDateChangedListener dateSetListener
= new DatePicker.OnDateChangedListener() {

* onDateChanged
public void onDateChanged(DatePicker view, int newYear,
int newMonth, int newDay) {

String dateOutput = String.format("Date Selected: %02d/%02d/%04d",
newDay, newMonth, newYear);
Log.i("Debug", dateOutput);

Friday, October 23, 2009

Hero Kernel Source

HTC have made the Hero Kernel Source code available. Not sure how much use it will be to you and me but its available here,

Monday, October 19, 2009

Another Eclipse/Android Issue

I ran across another small issue today. I tried import an existing Android Application into Eclipse and received the following error:

[2009-10-19 07:56:02 -]Android requires .class compatibility set to 5.0. Please fix project properties.

The solution is quite simple, select the following after right clicking on the project in the Package Explorer:

Android Tools >> Fix Project Properties

But importantly, you must restart Eclipse afterwards for the error to be resolved.

Hero Crash

My Hero crashed, I came to make a call and the phone would come out of standby. I first thought that I must have accidentally switched it off but it wouldn’t power on. So then I thought the battery must be flat so I plugged in the charger but the phone wouldn’t even charge. Starting to worry that the phone was dead and would have to be sent back, I resorted to removing the battery. Fortunately this resolved the problem but left me a little worried that this could happen again.

Saturday, October 17, 2009

Eclipse and Android Development Tools Issue

I attempted to install Eclipse and the ADT on my main computer at home and ran into a problem, I couldn’t get the Eclipse Plugins to install. I’ve installed this setup several times, on Windows XP, Windows 7 and Fedora 11 without any prior issues. My home computer is running Windows 7 x64. When I attempted to install the Plugins through Eclipse I got the following error:

Cannot complete the install because one or more required items could not be found.
Software being installed: Android Development Tools 0.9.3.v200909031112-12945 ( 0.9.3.v200909031112-12945)
Missing requirement: Android Development Tools 0.9.3.v200909031112-12945 ( 0.9.3.v200909031112-12945) requires 'org.eclipse.wst.sse.core 0.0.0' but it could not be found

I Googled the problem and got several results but none of the solutions resolved my problem. I then considered my other configurations and the difference in this instance. The main difference was that I had unzipped Eclipse into C:\Programs Files (x86)\. On the other machines I had unzipped Eclipse into C:\Programs where I tend to put applications which unzip rather than install through a Setup progam. Anyway this appeared to resolve the issue and the ADT successfully installed. I’m not sure if this issue is just related to x64 Windows 7 or whether it occurs with x86 or even Vista for that matter. Disabling the UAC may also have resolved the problem.

Wednesday, September 23, 2009

Hero ROM Update

I updated the Rom on my Hero today. I didn’t want to root my phone yet so waited for the official Orange update from HTC. I prepared my Hero by deactivating my Copilot installation and backing up all my settings, calendar, etc using MyBackup. I used the free version of MyBackup which works for 30 days and stores all settings on the SD card.

One concern I had was how the paid apps would be handled. I have two paid apps, Copilot Satellite Navigation and BeyondPod but I wanted to be sure that I wouldn’t have any issues reinstalling these two applications. I know from the Windows Mobile version of Copilot that’s its better to deactivate Copilot before updating the phones ROM and then reactivating afterwards.

The update went smoothly and took much less time than the estimated 10 minutes that HTC quote. I used a Windows 7 machine running the candidate release. I had read about people having problems performing the update with Windows 7 but I didn't have any issues althougth I ensured that I ran the update as Administrator.

Fortunatly reinstalling the applications after the update was easier than I imagined so long as you use the same Google Account as you used before the update. If you do this then when you go to the Android Market Place all your previous downloads can be found under ‘My downloads’ so you don’t even have to search for them again. I then selected each in turn and installed them. In the case of BeyondPod you also have to download BeyondPod Unlock Key which is the part you pay for. Wtih Copilot, the first time I ran the application it asked me to activate which I performed over wifi from the device and a few second later it was activated. BeyondPod was very simple because all the settings and podcasts must be stored on the SD and appeared once the program was reinstalled.

Wednesday, September 9, 2009

Hero 3.5mm Jack Socket

I thought I'd broken the 3.5 mm Jack Socket last night. When I plugged in my headphones the sound stilled played though the speaker and the headphones icon was missing from the Status Bar. I tried another set of headphones in the hope that the headphones had broken and not the phone but no luck either. As a last resort I rebooted the phone and this fixed the problem so it appears that the headphone socket includes a software switch with a bug in the code. Hopefully the new firmware will fix this issue too.

Tuesday, September 8, 2009

Coding with Performance in Mind

The link to the following post makes interesting reading whether you are an Android game developer or otherwise:

Hero Update

There appears to be an update to the Hero:

Personally I've never had an issue with the speed of the device but I did previously have a Windows Mobile device which really crawled at times. I have read that the speed of the SD card can make a difference where the slower cards produce a lag.

And they've fixed the clock because I found it annoying putting the clock back so it could flip forwards even though you only left the screen two seconds earlier.

Monday, August 31, 2009

Out of the box

It took me at least two days to realise that I'd configured the phone and started using it without having to connect it to a PC. It's my understanding that a brand new iPhone must be connected to iTunes on a PC/Mac before you can do anything with it. Windows mobile isn't much better, needing to be connected to a PC to transfer contacts. Admittedly I'd prepared for Android by uploading all my contacts to Google before the phone arrived. Then it was just a simple case of entering my Google login and the contacts arrived on the phone along with my calendar.

Application Lifecycle

One of the major improvements that Android has over current Windows Mobile is the Application Lifecycle Management and you don't need to be a programmer to appreciate this. There are various methods that your application can implement to handle this management. The one I most like is OnPause(). OnPause() is called as soon your application looses its focus to the user. When this method is called it is the programmers responsibility to ensure that current state of the application is stored in case the system closes the application to free up resources.

My first experience of this as an Android User was playing media. I spend a lot of time listening to podcasts and on Windows Mobile there was nothing more annoying than being part way through a podcast only to have the system close the application because you have switched applications to read a text message. In the end I had to guess when I thought I was running out of resources and try to remember the position of the podcast. If the media player closed I had to start the podcast again and try to jump the last part I was listening to, which isn't easy in a two hour podcast. The other advantage of this is if you switch the device off then the current position is also stored. Again Windows Mobile doesn't handle this.

Saturday, August 29, 2009

Starting with Android

I've now had a couple of weeks with the HTC Hero and I have say I'm really impressed. It's worlds apart from the Windows Mobile phone I had before. Everything is much slicker and feels more integrated. It's great to be able to do everything without having to pull out a pointer. The iPhone guys will be saying yes but we've been doing this for years and yes I agree but more on why I didn't go with the iPhone in a later post.

My main aim of this blog is to document my experience with Android mostly from a programmers point of view. I'm currently learning to program on the platform and want to communicate my experiences. In my day job I mostly code in Java these days so for me Android is ideal. I have in the past coded for Windows Mobile mostly in the days when it was called Pocket PC, so I can give some perspective on the systems.