vrijdag 26 november 2010

Write your own android application on an HTC mobile

I've just bought my new phone a HTC desire and i really wanted to write an application on the phone.
I discovered that its quite simple to write a program in Processing and a lot of fun. Processing is a language based on JAVA and used by many artist. It's actually a very simple language. You can write an applet in 10 lines of code. It is very well documented and there are by default a lot of little examples. For the advanced users there are many libraries available. If you have a mobile phone with android version 2.1 or higher you can start immediate. If your version of android is too low you can find on the internet how you can update the android version.






Installing Processing

Go to http://www.processing.org/ click on Downloads
Scroll down and goto the Pre-Releases (now 0191)
Choose Windows, Linux or Mac OS X download and install the program.


Install Android SDK

download the program and install it.
Install all available packages
Don't worry about Virtual Devices. Processing wil make one for you.



Settings on the Phone

Set the following option:
Menu -> Settings -> Applications -> Development -> USB debugging
Check that Android is version 2.1 or later
Menu -> About the phone -> Software Information -> Android version
Connect your phone with a USB cable to your PC or laptop.


Writing youre first Processing Android program

We are not really going to write a program but we will use one of the many examples that came with the program.

Launch Processing
Load the sample program:
Choose File -> Examples -> Basics> Input -> Mouse2D



void setup() 
{
  size(200, 200); 
  noStroke();
  rectMode(CENTER);
}


void draw() 
{   
  background(51); 
  fill(255, 204);
  rect(mouseX, height/2, mouseY/2+10, mouseY/2+10);
  fill(255, 204);
  int inverseX = width-mouseX;
  int inverseY = height-mouseY;
  rect(inverseX, height/2, (inverseY/2)+10, (inverseY/2)+10);
}

Run the program
Click Sketch -> run (or the arrow in the corner) to look at the program.


Running the application Mouse2D

First we have to set the program in Android mode:
Click Android -> Android mode

Watch the program in the emulator
Click Run

Check the program on your phone
Click Sketch -> Preset

If all goes well the program itself pops up on your phone.
Even if you pull out the USB cable, program will stil be present on your phone.

have fun!


Links

software development tool android: http://developer.android.com/sdk/index.html
Installing Android: http://wiki.processing.org/w/Android

Geen opmerkingen:

Een reactie posten