Google Android Development Agency SASS

Wednesday 9 December 2009

NUnit and App.config

Here's the problem: You have a project which you want to unit test with NUnit but the project relies on some appSettings or other config data normally loaded from app.config or web.config. You know the sort of stuff, connection strings, usernames etc.

When you run your code in NUnit you get a NullReferenceException when you try to access your config, it's like it's being ignored.

I come across this problem quite often but I always have to refresh my memory of how I fix it. Well there's two ways, but only one I can get to work reliably:

1) When you create your nunit project, rather than clicking Project-> Add Assembly, just drag your DLL from Windows Explorer onto NUnit. After doing this it'll pick up the assembly.dll.config file for your assembly. I couldn't get to work reliably though, it would work once and then fail.

2) You need to have a config file named the same as your nunit project and located alongside. So in my case I have com.sass.ecommerce.tests.nunit and alongside it my assembly (com.sass.ecommerce.tests.dll) and my renamed config file, com.sass.ecommerce.tests.config.

Doing it the second way gave me more reliable results and I could access my config file no problem from my unit tests.

Tuesday 1 December 2009

Tub Thumper Pro for Android out this week

At long last, we're looking at releasing Tub Thumper Pro for Android this week.

We've been into Android Development since day one and I've been constantly suprised at the amount of positive feedback we've had from the first version of Tub Thumper. We receive emails daily asking us about the pro version so I'm hoping it's going to be well received.

I'll put some more details online once it's live in the Android Market, but here's a screenshot of the sequencer interface in the meantime, which is one of the coolest new bits.


Tub Thumper Pro Sequencer Screenshot
You'll need at least Android 1.5 to run it and a touchscreen device. It's pushing the low-level audio features of Android with this tool, although I already have plans for Tub Thumper Pro 2! Watch this space...

At last! A good UML Editor for Visual Studio

For years I've been trying various different UML/CASE tools for designing .NET based solutions and until now I've always been left diasappointed. (I've not tried the new in-built tools of Visual Studio 2010 yet...)

This week I've been working on an e-commerce system for a client of ours who have chosen to use Sagepay as their payment gateway. Their site is built on the Kentico CMS platform and the Kentico E-commerce system doesn't support Sagepay out of the box, so basically I'm designing a payment provider for it.

I decided to try once again to find something decent to do Use Case diagrams, Activity diagrams, ST diagrams etc in so that I don't have to resort to Visio and Word as always.

Praise Jebus! Something good at last in the form of Tangible T4 Editor for Visual Studio. This is a plugin for VS.NET which allows you to create half-decent looking UML painlessly.

Here's an Activity diagram for the aforementioned e-commerce system I'm working on:




The only gripe I have so far is with the Use-case diagram tool; it would be really nice to be able to double-click on a use-case to open up a text-view of the actual use case allowing me to document the steps and pre and post conditions.

Here's the best bit: THERE'S A FREE VERSION!

Friday 27 November 2009

Android AudioTrack source

I've been doing a lot of work optimising our audio playback on Tub Thumper Pro for Android this week and I constantly find myself referring back to the C++ source for the OS to help solve latency issues.

For anyone doing work with the AudioTrack object, it's worthwhile bookmarking the source online so that you can browse it whenever you hit a problem.

Here's two links I find really useful:

Incidentally, I've found that the best way of getting low-latency polyphonic audio is to subclass AudioTrack and call finalize() yourself after you're done playing; I was seeing more "write blocked for xx seconds" messages before I did this, although it may be co-incidental.

Thursday 26 November 2009

Useful tool for building Android user interfaces

Android user interfaces are built using XML and the support for graphically laying these out in Eclipse is limited to say the least. (There are many things wrong with Visual Studio .NET but at least the UI builder is reasonably well sorted...)

A while back I came across DroidDraw - a third party tool for prototyping UIs. I think I must have had an early build back then because it had some issues, but I downloaded the latest build today and it's now hugely useful.

If you want to throw some Android user interfaces together head over to http://droiddraw.org/ and try it out. It's the tool Google should have included with the SDK!

Tuesday 24 November 2009

Android Activity States and State Transitions

I wanted to tidy a bit of our Android code up recently to make sure that each Activity was handing it's state properly and to make sure that things were getting cleaned up when the Activity was done.

Before doing this it was important to fully understand the lifecycle of an Android Activity and to understand the state transitions that will and can occur within one.

An Android activity basically exists in one of four states:


Here's a bit more detail about each of these states:

Active
The Activity is in the foreground of the screen and is interacting with the user

Paused
The Activity has temporarily lost focus behind a new non-fullscreen or transparent Activity. In this state is retains all of it's state, however, if Android detects a low-memory situation it may be killed.

Stopped
The Activity is totally obscured behind another Activity. Again it retains it's state, but is much more likely to be killed at any point.

Finished
The Activity has been closed, either by Android or by calling finish(). The state it had dies at this point (unless you explicitly save it).


There are seven events in the Android Activity Lifecycle which give you a bit of control over what happens during each state transition.

onCreate(Bundle icicle)
Fires when the Activity is first launched. You would normally do all of your setup in this method. You can also retrieve any previously saved state from the supplied Bundle.

onStart()
Called when the Activity is becoming visible to the user, for example when another Activity higher in the stack has closed.

onRestart()
Called after the Activity has been stopped and is being restarted.

onResume()
Called when the Activity is becoming interactive to the user.

onPause()
Called when Android is about to start resuming another Activity. You would normally use this to stop anyting dynamic that is happening in your Activity, e.g sounds playing, animations happening.

onStop()
Called when the Activity is no longer visible, usually because another Activity has started over the top of it.

onDestroy()
This is the last breath of your Activity, called just before Android pulls the plug on it.

Here's a state transition diagram to show the sequence of states and the events in between:



isDaemon and Java Threads

Whilst pondering the best way to organise the threading structure of our upcoming Android app Tub Thumper Pro, it struck me that there is a smattering of confusion (at least in my head!) over whether a thread is a daemon or not.

In Java, there are two types of threads Daemon Threads and User Threads.

User Threads are the ones you'll most commonly use; these provide the mechanism of running parallel code in your applications. Most importantly - when the application is terminated, the JVM waits for all user threads to finish before quitting.

Daemon Threads are generally used for service-level processing rather than application-level code. The JVM will not wait for any daemons to finish before quitting your application, they will run behind the scenes until the JVM decides there's nothing else to do and terminates.



Monday 23 November 2009

Low latency audio playback in Android

One of the things which bugged me immensely about Android was it's lack of low-latency audio playback and a low-level audio API.

Unlike the iPhone, Android developers were stuck with high-level media player objects which basically only allowed you to chuck an MP3/OGG/Wav their way and hope for the best.

Well not any more my robot loving amigos!

After pulling my hair out trying different designs and playback algorithms working on the sequencing function of Tub Thumper Pro for Android, I finally found what I'd been looking for; an object for working with sample-level data, just like we've been doing on the iPhone.

android.Media.AudioTrack

I mean, it's not perfect, but here's what we're doing to run samples directly to the hardware without all of that mediaplayer-esque overhead (I've edited it to make it make sense outside of our app, but the theory is there):


//--load the sound file from the resource identifier into a byte array (c is Context)
InputStream s = c.getResources().openRawResource(resourceFile);
soundData = new byte[s.available()];
s.read(soundData);

//--setup an AudioTrack object, this one is running at 44.1Khz which worked best for us.
AudioTrack oTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 44100,AudioFormat.CHANNEL_CONFIGURATION_MONO,AudioFormat.ENCODING_PCM_16BIT, intSize,AudioTrack.MODE_STREAM);

//--turn the audiotrack on
oTrack.play();
//--write something to the audio track, in this case the entire buffer
int playVal = oTrack.write(soundData,0,soundData.length);
//--we're turning it off here
oTrack.stop();

Our Android app in Top 100 Best Smartphone apps of all time!

Well oil my bike. Our first Android app, Tub Thumper, has just been listed in the "Hot 100 best apps" by T3 Magazine.

We still get plenty of feedback about the free version (mostly positive thankfully) and we're trying to get the Pro version out ASAP.

I'll be very interested in seeing how it runs on my Motorola Droid phone, when it arrives, given it has a multitouchscreen...

You can view the gallery here: http://www.t3.com/feature/t3s-hot-100-apps


Update - here's a shot of the app at number 1 in this months T3 magazine!

Google Chrome OS Beta first install

No posts for a few months, mainly due to the lack of mobile development action over here!

Just downloaded the first build of Google Chrome-OS and installed it on a VMWare virtual machine.

First impressions: Booted up very very quickly. I can definitely see the use for it in low-cost netbooks and for couch surfing. However, there are a couple of things which I can foresee might scupper it: No iTunes/Media playing and no image editing. All very well sticking your photos on Picasa or Flickr, but how are you supposed to get them off your device and edit them without any means of installing desktop editing software, or without provision for storing files locally?

I currently use a Macbook for surfing on the couch and for dragging photos off my cameras and onto Flickr. I would have considered Chrome-OS an alternative for this (farewell Apple at last...) but without just a few more niceties I can't make that switch.

Anyway, here's some screenshots of the login screen and the first screens you'll see.






All those apps you see above are of course just links to websites, although Google have mentioned in their design documents that they are hoping to use popups for sub-tasks, like the one shown below.



If you want to try it yourself, head over to http://discuss.gdgt.com/google/chrome-os/general/download-chrome-os-vmware-image/ and grab the VMWare image. (If you have trouble logging into the virtual machine, try the username "chronos" without a password).

Tuesday 28 July 2009

Get Google Latitude on UK T-Mobile G1

I don't know why, but despite the regular firmware/OS updates for Android and the G1, Google has not yet released its Latitude feature for Google maps on the UK version of the device.

Thankfully, it's dead easy to get, without requiring root access to the hardware or replacing the T-Mobile shipped OS.

To get it, all you need to do is download the "Google Maps" app from Google Market; this will replace your current Maps app with a new version, which includes Latitude.

Thursday 21 May 2009

Editing Umbraco in canvas mode gives error

I hit a slight quirk with Umbraco today. One of the features of Umbraco is its ability to edit a page in "Canvas mode". This means your page opens in a new window and is rendered as if it was a website, but with a content editor for you to edit your content in; much nicer than using that small white editor.

Today I fired up the canvas editor for one of the pages in a new site I'm working on, only to be met with:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Hmmf. It's because in the footer of the website I'm doing:

<%=DateTime.Now.Year%>

To output the current year. Umbraco is attempting to modify the controls collection of the page to create the editor, which is not allowed when using inline code blocks.

The workaround is a bit sneaky, but simple. All you need to do is change to the databinding syntax for echoing, like this:

<%# DateTime.Now.Year %>

Now all is well, the control collection can be modified and you can bask in the glory of the Umbraco canvas editor.

Tuesday 19 May 2009

MIDI Playback in Android Cupcake

If, like me, you've been wondering why the audio support in Android was so poor, you'll be pleased to hear that Android 1.5 (Cupcake) addresses some of the issues.

I'll write a more in-depth post once I've gone through some real world examples, but one thing which I'm currently reading up on is the in-built MIDI support.

Rather than just stick a bog-standard MIDI engine in Android, the Google engineers have chosen to include a JET playback engine, which allows musical synchronisation of clips and seamless playback. It's mainly tailored towards game playing as it allows you to script the clips about to played back to tie in with the gameplay, but I'm already thinking up some cool musical ideas for it.

Have a read of the documentation on Android.com, at http://developer.android.com/guide/topics/media/jet/jetcreator_manual.html

New Tub Thumper Version

Today we released a minor update of our Google Android application Tub Thumper.

Tub Thumper is a touch screen drum machine for the Google Android platform and has proved immensely popular since its release last November.

This version is a minor release with a new hip-hop style drum kit, to wet people's apetites for our upcoming major release.

We've been hard at work developing Tub Thumper Pro, which will feature many new cool things. Notable assignable drum pads and the ability to sequence beats, similar to using a Roland TR-909 drum machine.

As it's not yet ready I'm not saying much more, but here's a sneak preview of assigning some drum sounds:



We're aiming this release for the Cupcake build of Android, which will have hit everyone's phones by the time we release it.

At SASS, we spend most of our time working on client projects; developing web and mobile applications for clients. It's nice to get a break from this to work on some of our own projects such as Tub Thumper and it gives us a great opportunity to try out new development ideas and increase our knowledge as developers. There does not seem to be a huge amount of Android developers around Manchester and Cheshire so it often feels like we're out on our own, but we'll continue to experiment and release new Android apps to showcase our ideas.

You can grab Tub Thumper from the Android Market. Just search, or check out the most popular Multimedia apps.

Friday 8 May 2009

Changing the color of the iPhone navcontroller bar

You may have noticed some apps on the iPhone have different colored navigation bars. I didn't have any reason to play with this, but being an inquisitive iPhone developer I wanted to know how it's done. I hadn't even noticed that you could customise this in Interface Builder, but it turns out it's really simple.

Just open up your root view controller (MainWindow.xib) in interface builder. Now click on the NavController icon:



Now open up your inspector panel and look at the Top Bar drop down. You can select the color of the Nav Controller bar there, set it as either Normal (blue grey), Black or Translucent.



Now you can have a cool black nav controller too!

Thursday 7 May 2009

UK G1 Owners - Get Android Cupcake early!

The rumour mill has been in full swing with regards to the early push out of Android 1.5 "Cupcake" to UK T-Mobile G1 users. Whether or not they really have started the push remains to be seen (I've not had it) but the folks over at Andblogs.net have posted how you can get it early.

First things first, grab the update: UK 1.5 Cupcake Update (CRB17) (5)


Save it to the sd card, named “update.zip”. (If you use windows, be sure you aren’t naming it something like “update.zip.zip”.) Reboot your phone in recovery mode (hold down ‘home’ while booting until you see the diamond warning.)


Now time to update! Press Alt-L. (This will turn on logging, so you can see what is going on.) Then Alt-S will apply the update.zip from the sd card. When it finishes, it’ll reboot.



I'm just trying, fingers crossed!

Oh, and don't blame me if you brick your phone, like I said - I've not tried it yet! Don't know if this works for countries other than the UK either, I'd suspect not but feel free to comment if you know otherwise.

Update!



My phone exploded in a huge fireball! Just kidding, after a nerve wracking few reboots with some cryptic logos I finally got a shiny new animating silver Android logo and I'm now smothered in delicious Cupcake.

Here are a couple of money shots:

The much-talked about touchscreen keyboard.


New homescreen icons (and check out my sweet (get it?) NIN Downward Spiral wallpaper, in your face iPhone!):


In the inimitable words of fake James Hetfield, sprinkles GOOD!

Wednesday 6 May 2009

iPhone GPS programming is easy

Before I looked at GPS development for iPhone I was bracing myself for an onslaught of complicated hardware commands, old school C data structures and binary arithmetic. Queue a flashback to the CoreAudio learning curve...

Almost unbelievable it's not the case though; Apple have made things pretty straightforward for a change!

The first thing to do, and the key to it all, is to create a class which conforms to the CLLocationManagerDelegate specification:


@interface MyLocationManager : NSObject <CLLocationManagerDelegate> ...


The CLLocationManager delegate needs to contain a method which is called to notify it that the location has been updated. Basically, this:


- (void) locationManager:(CLLocationManager *) manager
didUpdateToLocation:(CLLocation *) newLocation
fromLocation:(CLLocation *) oldLocation {
...


Now within your method implementation you can access the coordinates of the old and new locations with:


newLocation.coordinate.latitude;
newLocation.coordinate.longitude;
newLocation.altitude;


Obviously you'll need to do a bit of jiggery pokery to get those raw figures into a useful state, but that's down to your own app logic. In terms of getting the GPS coordinates nothing could be easier!

Apple have a very good sample project in the developer library called LocateMe. I'd suggest you download it and study the code to learn the ins and outs of GPS programming. It took me literally 10 minutes to get the basics going.

Next stop - Android GPS development!

Tuesday 5 May 2009

Lots of weird errors with iPhone 3.0 SDK Beta

Today is the first day I've been doing iPhone 2.2.1 development alongside the iPhone 3.0 beta and I can tell you that things have not gone to plan.

The first nightmare I encountered was to do with the naming of my 2.2.1 app. The name has a space in it (which is not technically allowed I now understand although nothing has ever moaned before). When I tried to compile the app using the 2.2.1 framework I get the error:

com.apple.tools.product-pkg-utility: error: CFBundleIdentifier 'com.yourcompany.Project_name' contains illegal character '_'


The first thing to note here is that the only thing that's changed on this Mac since the last time I compiled the app is that I've installed the iPhone 3.0 beta SDK.

The only way I've found to get around this so far is to manually edit the "Identifier" field in the project settings to remove the space, and hard code to package identifier (not good).

The next weird thing happened when I tried running the app on a connected iPhone. (In fact the iPhone that I've been using for all of the development up until now).
When I first ran the app from XCode I received the error "The application is already installed on the device".

Obviously the app is already installed, I've been developing it for months! Normally XCode would just overwrite the app and keep all of your application settings and data, but now it seems I have to manually delete the app from the phone before hitting build and go. Extremely frustrating!

This last problem seems a little unpredictable too - I've just ran the app twice from XCode without uninstalling it and it hasn't popped up the error yet. We shall see...

I should state that all of this is with me targetting 2.2.1, I haven't ran it under 3.0 yet.

If I come up with anymore solutions or problems, I'll update this post but for now I'd better get back to making it work!

Friday 1 May 2009

iPhone 3.0 Features

After a mammoth 2.14Gb download, the iPhone 3.0 SDK beta finally landed on my Mac.

I'm not taking any chances installing it on my iPhone yet, but there didn't seem to be any problem running the simulator in 3.0 alongside 2.2.1.

On the surface, things seem like business as usual. The one major thing you notice is the new Search function of the homepage.



You now get a little magnifying glass icon on the main screen:

Swiping the screen left gives you a search box. Weirdly, this only seems to search the installed applications. I had assumed that it would be similar to the search widget on Android, whereby you can search Google straight from your homescreen. Certainly this doesn't seem to be the case for the simulator anyway, we'll see when I get it running on a phone.



With over 1000 new API's there are clearly some major new things going on with iPhone 3.0. To get you ready for the change, Apple have created some good documentation about ensuring backwards and forwards compatability with your apps. Log into the iPhone developer center and check them out.

Thursday 30 April 2009

A bit about me

Since I've had this blog for a little while now, without much background about me, I thought it might be worth sticking a post on to talk a bit about my background.

I've been working in software development for over 10 years, mostly based in and around Manchester and Cheshire.

I'm working these days as Senior Technical Architect at the Cheshire based agency SASS Digital.

I spend much of my time focusing on mobile development, notably iPhone development and Google Android development. We pioneered the Tub Thumper drum machine app on the Android platform, an app which was very successful and attracted interest from Google, HTC and T-Mobile. We're still working on Tub Thumper Pro, this will take advantage of the new audio API's of Android Cupcake so watch this space!

We've also recently been working on a top-secret audio app for the iPhone platform, I can't give away any details except to say that it's for a major client and once it's released should be awesome.

Prior to working here I was Technical Architect (amongst other things) at 3T Productions Ltd in Manchester, a sub-division of the mighty RM (Research Machines). I spent the best part of 10 years working at 3T, for huge clients such as the BBC, the DfES, Ofsted, Penguin Books and Harcourt publishing.

I gained a wealth of experience working in technologies such as ASP.NET and SQL Server and also with standards such as e-GIF and SCORM. Much of my work at 3T was e-learning based, an industry in which we broke new ground with every project.

In my spare time I play lots of guitar and record music, and spend a lot of time working on and driving rusty Citroens, such as my DS. There's a picture of my hotrod styled 2CV below.

My hotrod style 2CV

If you're interested, you can follow me on:

Twitter
Flickr

Enough about me anyway, back to the mobile development!

Showing the debug trace in Umbraco

Whilst developing with Umbraco, you'll quite often come across errors in UserControls where all you'll see is a big red box with not a lot of info as to what the error is and where it occurred.

It's easy to find this info when you know how; just add umbdebugshowtrace=true to your querystring and you'll see the debug stack trace, allowing you to locate the problem.

Friday 24 April 2009

Problems with Android 1.5 pre release

Just been trying the pre-release of Android 1.5 and hit a problem with one of the new features of the emulator.

With this version, you can create "Android Virtual Devices" (AVDs) which allow you to run multiple configurations of the emulator side-by-side without having to run long command line switches.

I'd created my new 1.5 AVD using

android create avd --name cc --target 3 --sdcard 16M --skin HVGA

but then trying to invoke (emulator @cc) it gave the error

could not locate a virtual device named 'cc'

If you run into this problem, you can diagnose what's wrong by running

emulator -debug avd_config -avd cc

Running this gave me a weird path problem, the emulator was trying to find the .ini file for my AVD in c:\Users\Andy\ instead of e:\andy\. (I'm on Vista and my profile is on drive e:\).

To fix this, all I had to do was create a new environment variable ANDROID_SDK_HOME and point this at the moved profile directory. Restarted the command line so that it would register the variable and all was well.

Now for some Cupcake fun!

Tuesday 21 April 2009

Using % symbols in NSStrings

Normally, when you use the '%' symbol in an NSString, it's because you want to use a formatter to format some other variable and insert it into the results string.

For example

NSString *myString = [[NSString alloc] initWithFormat:@"Number : %d",5];

Would yield the string "Number : 5".

However, we've had a few cases where we need to output a percentage in a string, e.g. "50%". I spent a few minutes searching for complicated solutions, before it dawned on me that all you need to do is escape the % sign, thus telling the compiler that you don't want to invoke a formatter:

NSString *myStrWithPercent = [[NSString alloc] initWithFormat:@"%@%%",myNumber];

Yields "50%". The % sign escapes the second %. Simples!

Wednesday 1 April 2009

Problems with iPhone Ad-hoc Provisioning

We recently had a problem here at SASS Digital whereby an app we currently have in development for the iPhone would not install on a handset, despite the correct provisioning profiles being in place.

To put this into context, we had created an ad-hoc provisioning profile, signed by myself (as Team Leader) and associated this with the UUID of the handset in question. The provisioning profile had been successfully installed on the handset (showing as verified in the Profiles area of the phone) but when we tried to sync the app we got the fateful error:

application could not be verified

The solution, it turns out, was simple:


  1. In xCode, create a new file, choosing "iPhone OS -> Code Signing -> Entitlements" as the type

  2. Call the new file "entitlements.plist" and then open it in xCode

  3. You will see that this file has only one option; get-task-allow. Make sure that this is not checked.

  4. Now, make sure you have your chosen target selected, and click Edit Active Target

  5. In the "Code Signing Entitlements" field, enter "entitlements.plist"

  6. Save everything, clean the build and compile



This solved the problem for us, our app installed on the phone using our pre-installed provisioning profile. Praise Jebus!

Tuesday 10 March 2009

How to: building apps on a jailbroken iPhone

With Apple in chaos when it comes to handling membership to the ADP, sometimes we as developers have no choice but to bypass the official process and get things working anyway we can.

I've just had the pleasure of getting an unsigned iphone app to run on a jailbroken iPhone and given the myriad of different methods out there I though I'd write a quick how to.

I'm assuming you're starting out with a standard (locked) iPhone 3G. (I've not tested this on iPod touch). I'm assuming you're at v 2.2.1 as that's all I've tried this with. You're going to need an Intel Mac - I couldn't get this to work on a PowerBook, even though I can write apps and run them in the simulator on the Powerbook. You also need OS X Leopard, thanks Apple :-(

For the prupose of this tutorial, I'm focusing on getting an existing app to run on an iPhone, to create one from scratch you need to download and install the Pwned developer templates, which are easily located using Google...

  1. First off, you need to jailbreak your iPhone. The easiest way I found was to use QuickPwn. DO NOT USE THIS IF YOU WANT TO UNLOCK YOUR iPHONE AT A LATER DATE!! (See QuickPwn website)
  2. Download QuickPwn and follow the onscreen steps, I had my iPhone jailbroken after about 5 minutes.
  3. Fire up Cydia on your newly jailbroken iPhone, and add a new "Source" in the Manage section, using the url: http://www.iphone.org.hk/apt
  4. Locate the package "Mobile Installation Patch" version 2.2.1 in the "Tweaks" section of Cydia and install it
  5. Reboot your iPhone. It should now be ready to accept any application.
  6. You need to create a self-signed certificate in your keychain to sign your apps with. To do this, run the Keychain access utility from the Utilities folder on your Mac.
  7. In keychain access, click on Certificate Assistant -> Create a certificate from the Keychain access menu.
  8. In the certificate name field, enter "iPhone Pwned Developer" and choose "Self Signed Root". Check the "Let me override defaults" box and click continue
  9. On the next screen, enter a serial number (Any number will do as long as it's not already used in a certificate). Change the certificate type drop down to "Code signing"
  10. Fill in your details on the next screen and then click continue through the rest of the screens.
  11. Once you get to the end, you'll see a new certificate and key pair called "iPhone Pwned Developer". You can now close the keychain access utility.
  12. Next, locate your projects "Info.plist" file and add the following: 

    <key>SignerIdentity</key>
    <string>Apple iPhone OS Application Signing</string>


  13. Save the file and run XCode
  14. Open your project properties in Xcode and add two user defined settings as follows:

    PROVISIONING_PROFILE_ALLOWED NO
    PROVISIONING_PROFILE_REQUIRED NO

  15. In your project settings, make sure that your code signing identity is set to "iPhone Pwned Developer". For reference, my other important settings were: Valid Architectures=armv6, C/C++ Compiler=GCC 4.0
  16. Now, click open the Organizer window and verify that your iPhone is listed under devices. If it isn't try rebooting it and restarting XCode, it should appear. (Obviously plug the cable in first...)
  17. Once your iphone is connected, make sure you set your target to "Device - 2.2.1", clean your build and then click "Build and Go". Your app should now run and appear on your phone!

Even if this doesn't help anybody else, it at least gives me a record of what I did to get things going. It took me two days of messing around to get this working (admittedly some of that was re-installing OSX on the MacBook).

One final thing - I take no responsibility for what you do with this, nor if you brick your phone, wipe your hard drive or blow up the office. If you're not sure what you're doing, don't blame me when things go wrong!




Thursday 19 February 2009

Android RC33 for the UK coming soon

Still on RC8 in the UK
Whilst US users of the T-Mobile G1 received the latest update to Android, the so called "RC33" release earlier this month, UK users have been somewhat left in the dark, still stuck on RC8.


RC33 brings a number of cool things to Android, notably voice search and Google Latitude. Note that this isn't the long awaited "Cupcake" branch of Android - it'll be a while (if ever) until we get that on a G1.

According to a comment on this blog post, someone called T-Mobile support and was told to expect the update "sometime around February 20th".

Let's hope they're not lying - I've been developing on Android SDK 1.1 without a hardware device to test it on!

Incidentally - if you want RC33 but don't want to wait, you can follow the instructions here to get it. Don't come crying to me if you brock your phone though... ;-)

Tuesday 17 February 2009

Second Android Handset unveiled


During this week, the Mobile World Congress has been in progress in Barcelona, and whilst we were expecting to see a whole raft of Android gubbins, it seems that the only big news is the release of the second Android-powered handset, in the form of the HTC Magic.

The Magic will be available exclusively on Vodafone and will be the first handset to feature the Cupcake branch of Android.

This is major news for us here at SASS Digital as Cupcake features signficantly improved Audio-APIs which will help no end in our ongoing development of music applications.

The big question is - will it support multi-touch? I suspect I know the answer...

Accessing UI elements from background threads in Android

One of the challenges I've faced this week in Android has been how to access and change the UI from a background worker thread.

By default in Android, anything created in the onCreate() method of an Activity runs in the UI thread. Whilst this is good for some apps as it keeps the application profile down, for anything requiring a degree of performance it's not ideal.

We're working on a real-time music application here at SASS Digital and hence a lot of our work is done in background threads. To make matters worse, we need to execute code at specified intervals whilst maintaining performance.

The problem is, you cannot modify UI elements from a background thread.

Android goes some way to providing the solution to this in the form of the Handler class. The Handler allows you to execute Runnable objects whilst maintaining access to the UI elements. It also provides the seemingly useful postDelayed() method which allows you to schedule some code to run after a specified interval, much like the setInterval javascript statement.

All was looking rosy until it turned out that the stability of the Handlers timing was questionable to say the least... I couldn't get it to tick away perfectly no matter what I tried, so I was back to using a java.util.Timer for my timings, which meant I had no access to the UI again.

The solution turned out to be pretty simple.

You need to create a new Handler object and overide the handleMessage method to receive messages from your background threads.


In my onStart() method of the Activity I added this:

Handler h = new Handler() {
public void handleMessage(Message msg) {
//--update your UI here
}
};


I then implemented my custom TimerTask which would perform my work in the background, passing the Handler to it's constructor. E.g


MyTimerTask mtt = new MyTimerTask(h);
Timer t = new Timer();
t.schedule(mtt, 1, 200);


Now within the TimerTask I can pass messages back to my main UI thread via the Handler:


public void run() {
//--send a message to the UI thread to update itself
Message msg = _h.obtainMessage(); //_h is my Handler reference
msg.obj = 1;
_h.sendMessage(msg);
}


As if by magic my main UI code receives this message and can be notified to update the UI. It runs a lot quicker than using the default Handler.postDelayed().

Update


If you use an inner instantiation of a Runnable rather than a seperate class you don't even need to use a messaging pattern, you can use the Handler object to directly call methods on your UI thread using the post method:



Handler h = new Handler();

private void updateGUI() {
//--do your gui work here
}

private void doMyBackgroundWork() {
//--this method will do your background work

//--use the handler to call back to your main ui thread
h.post(updateGUI);
}

private Runnable bgRunnable = new Runnable() {
public void run() {
doMyBackgroundWork();
}
};

Thread t = new Thread(null, doMyBackgroundWork,"BGThread");
t.start();



Very simple!