Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

103
Insight Developing for Mobile Devices Rob Miles Department of Computer Science

Transcript of Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Page 1: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Insight

Developing for Mobile DevicesRob MilesDepartment of Computer Science

Page 2: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Overview

Windows Mobile platforms> Introduction to the history and capabilities of mobile devices

Visual Studio 2005 and mobile devices> Practical : Creating a sample application (Secret Encoder)

Advanced Programming> Creating Casual Games for Mobile Devices> Practical : A working mobile game – StarLight space shooter

Page 3: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Windows Mobile Platforms

Introduction

Before we look at the process of development, we should look at the platforms themselves

> The origins of the Pocket PC and Smartphone> What constitutes state of the art at the moment> What the future holds

Page 4: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Pocket PC

Originally called the “wallet PC”

Launched in 1996 with Version 1.0 of Windows CE

Superseded in the following year with Version 2.0

Initially available in keyboard and keyboard-less versions

Page 5: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Breakthrough Pocket PC:Compaq Ipaq

This was the first device to deliver on performance, display and battery life

> 120MHz processor

> 32MB of RAM

> Flash ROM

> RS232 and IR ports

> 240x320 TFT colour display

Page 6: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

State of the art Pocket PC

Dell Axim V50s> 624Mhz Processor> 64MB RAM> 480x640 colour display> WIFI and Bluetooth> 3D Graphics accelerator

Windows Mobile 5 £150 less than the original

IPAQ!

Page 7: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Smartphone

In 2001 Microsoft announced that it would be launching a range of Smarpthones (codenamed "Stinger")

The Smartphones would be "Windows based"

The version of Windows in question was Windows CE 3.0

Launched in October 2002 with Orange SPV

Page 8: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Breakthrough Smartphone:SPV E200

First to deliver on performance and battery life:

> 32MB user memory> Built in Bluetooth support> Built in camera > Smartphone 2003 Operating System> .NET Compact Framework

Page 9: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

State of the art Smartphone: SPV C600

Launched in August 2005> 64MB of internal memory> Fast internal processor (200 MHz)> Small form factor > Runs Windows Mobile 5

The Imate SP5 version of this platform also has WIFI

Page 10: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Pocket PC Phone Edition

Combines PDA with phone> Launched in July 2002> 206-MHz Intel StrongArm

processor> 32MB RAM> Based on Pocket PC 2002

Page 11: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Breakthrough Device: XDA II

Launched in April 2004> 400MHz Processor> 128MB RAM> Camera> Bluetooth> Windows Mobile 2003

Page 12: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

State of the Phone Edition:XDA IIS

Launched in April 2005> Integrated Keyboard> Improved performance

Page 13: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Imate Jasjar

First 3G Windows Mobile Device

> Branded as Orange M5000> VGA resolution display

(640x480)> WIFI support> Two cameras> Windows Mobile 5.0

A viable desktop alternative

Page 14: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Other devices of note

Palm Treo> First Palm Windows Mobile 5.0 device> Available in USA with broadband network

speed> Being positioned as a “Blackberry killer"

Imate JAM> Very small Pocket PC phone edition> New form factor for Pocket PC

Page 15: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

The Future…

The development of the devices over the last few years has been amazing

The systems are going to get more powerful and more connected

Location based behaviour is now very easy to implement in systems

Page 16: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Visual Studio 2005 and mobile devices

Introduction

The key components The Smartdevice project type Language and Development options The project as an executable program Deploying to a target Simple debugging

Page 17: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Key Development Components

ActiveSync 4.1> connects the Smartphone device to the PC

Visual Studio 2005> provides development environment

Smart Device Developer Kits> provides development project types

SOTI Remote commander> provide a remote viewer for the mobile device

Page 18: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

ActiveSync 4.1

The precise version is important Manages the link between the PC and the

Smartphone Can use wired (USB or RS232), infrared

(IRDA) or Bluetooth connection to the developer PC

You do not need to partner with a device in order to develop for it

Page 19: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

ActiveSync Deployment

Visual Studio uses an ActiveSync connection to deploy programs and debug them

ActiveSync sets up a TCP/IP connection to the target device

If the connection does not support a native TCP/IP connection a private subnet is set up

Page 20: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

ActiveSync Private Subnet

The ActiveSync connection establishes an IP address for the connected device:

> PC Emulator: 192.168.131.75> USB Connected Device: 192.168.55.101

These connections allows programs on the Smartphone to originate connections

ActiveSync 4.1 will also connect to emulators and synchronise with them

Page 21: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Connection Limitations

The private subnet set up by ActiveSync does not allow external programs to originate a connection to the device

This is not a problem, since any application you write will run on a phone which you will be unable to connect to in this way because the GPRS IP address will not be known

If two Smartphones are to exchange information over TCP/IP this should be via a third party server or by using web services

Page 22: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

ActiveSync Connections

Universal Serial Bus (USB)> All Smartphones are shipped with a USB cable or cradle for

connection to a PC Infra Red (IRDA)

> Most Smartphones have an IRDA connection which can be used for ActiveSync

Serial port (RS232)> Some Smartphones are also equipped with a serial port which can

be used by ActiveSync. Note that programs on the Smartphone may also make use of this connection

Bluetooth> ActiveSync can connect using the Bluetooth serial port

implementation. This is configured as a serial port connection

Page 23: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Preferred Connections

USB is the most reliable Bluetooth is the most convenient, but can be

problematic to set up and maintain IRDA works surprisingly well, particularly with

notebook and tablet PCs The serial port connection will require a

special cable, and is declining in popularity

Page 24: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Visual Studio 2005

This provides the development environment for the mobile devices

Can create .dll libraries and executables Produces both managed an unmanaged

(native) code Also supports remote debugging in the target

(on both emulator and device)

Page 25: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

SOTI Remote Commander

Earlier versions of the mobile operating systems supported remote control tools which were provided in the Mobile Powertoys

> Window Mobile 5.0 does not support these

To write applications which use the target hardware (camera, phone, SMS messages) you need remote access to the device

I use SOTI Remote Commander: (www.soti.com)

Page 26: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Inside a Compact Framework Program

Because the executable is a .NET program you can use ILDASM and other tools to manipulate it

You could even create MSIL applications for the Smartphone if you wish

Page 27: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Deploying the Program

When the program is executed from within Visual Studio it is copied into a directory on the target device and executed from there

You can deploy the program just as an executable file if you wish, by copying it into a directory on the Smartphone using ActiveSync

Page 28: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Finding the Program

The more recent mobile phones are shipped with file browser programs you can use to find and run the executable directly

Pocket PC owners can use the built in file browser

Page 29: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Stopping a program on the target

The program can be stopped at any time If the program is running on a remote device it

will also be stopped If the ActiveSync connection fails Visual

Studio will display an error, but the program will continue to execute on the target device

Page 30: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Selecting the Target Device

The target device is selected from within Visual Studio

If you try to use a real device, and none is connected, the deployment will take a while to time out

Note the different display form factors

Page 31: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Debug and Release Mode

The program can be compiled for Debug or Release mode

This is selected from within Visual Studio

When using Debug mode a Program Debug Database is created alongside the program executable file

Page 32: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Debugging

The debug tools are very powerful You can:

> Pause an executing program> Add a breakpoint to an executing program without stopping it

These facilities work on the target device too You must however have used Debug mode to

build the application The Remote Display Power tool can be useful

here

Page 33: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

The Configuration Manager

You can create your own forms of configuration to customise your development

The manager is accessed from the Build menu

Page 34: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Project Properties

The Project Properties give you an even finer level of control of the project

This includes where on the target device the program is actually deployed

Page 35: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Smartphone Games Development

Secret Encoder Program

We are going to explore the development process by developing a simple program for the mobile platforms

This will allow us to explore input/output and program design

The work could be the basis of a student practical exercise

Page 36: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Introduction

The “Secret Encoder” Program

> Encodes text entered, based on a simple keyword

Will allow us to explore the issues of mobile development

> User Input> Output Display> Use of the Menu Buttons> Program termination

Page 37: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Encoder Program

Screen contains three areas:> Encryption key entry> Secret message entry> Output display entry

When the code button is pressed the key is applied to the message to produce the result

The encryption is performed using XOR, so that it is reversible

Key: mykeytext

In: password

Out: xwbqegg231

Code

Page 38: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Getting Started

Once the Smartphone extensions have been loaded you can create a Smart Device application

Call itSecretEncoder

Page 39: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Good Practice

Rename the source file from Form1 to SecretEncoderForm

> Note that the refactoring process automatically offers to rename the classes as well

Then change the text on the form from Form1 to Secret Encoder

> Use the properties of the form to do this

Page 40: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Encoder Project

First we have to add the data entry components for the program

The Visual Studio Toolbox holds only the components which are available for the Smartphone display

We are going to use Label and TextBox components

Page 41: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Encoder Form

Now add four Label and two TextBox components onto the form

Make sure they are given sensible names and aligned correctly

Page 42: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Field Traversal

The Smartphone application begins running with the most recently added TextBox selected first

Moving “forwards” through the fields actually moves towards the “oldest” TextBox

This might not be what the user will want You should add the lowest TextBox first

> Or make use of the tool to change the field order

Page 43: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Smartphone Tab Order

The Smartphone Tab order dialogue, selected from the View menu allows you to re-arrange the tab order of the fields on the form

Click on the fields in the order you want

Page 44: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Data Entry

The present program will run, and the user can move between the two entry boxes and type text into either

We now need a way of triggering the encode action

Page 45: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Adding Menu Keys

To add a menu key just click on the screen above the key and type the name of the key

The menu item is created automatically

Page 46: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Menu Keys Names

Once you have added the keys to the form you can type menu selections onto them by clicking on the “Type Here” item

Page 47: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Smartphone Menu

The menu key is displayed as shown

We now need to bind an event to the key press to perform our encode action

Page 48: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Menu Names

I rename menus (and other components) so that the names of their event handlers make sense

You should do this as soon as you have created one

Page 49: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Adding the Event Handler

Double click on the menu item to create an event hander for it

Page 50: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Encode Action

I have created a method to perform the encode action I could have placed this code inside the event hander

itself, but it is more flexible to create a method to do the job:

This calls an encode method which actually performs the translation of the text itself

Page 51: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Testing the program

The initial version of the encode method simply returns the original text

This allows me to test the program and ensure that it works correctly

Page 52: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

The Encode method

Page 53: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Secret Encoder

The encryption works, but it is a very weak method

Note that the space in the input reveals the key character at that position

I leave it to you to create a better one!

Page 54: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Exiting the program

At the moment there is no way to exit the program on the Smartphone device

We can stop it with Visual Studio, but the user will not be able to do that

It is very easy to add an exit menu option

Page 55: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Stopping an Application

We can use the standard application termination method to stop the program:

This frees off any resources and exits the program cleanly

Note that the Windows CE guidelines aren’t keen on you stopping your programs (but I do it anyway)

Page 56: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

TextBox Key Entry

You may wish to not show the password when you are using the program

As with standard Windows Forms, the TextBox component can be set to allow password entry

Page 57: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Debugging

The program can be debugged in exactly the same manner as any other Visual Studio application

Any exceptions which are thrown are trapped and you are given the option to debug

Page 58: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Running on the PC

The application will run on a standard PC

Note how the behaviour of the menu has been adapted for a Windows Form

It is often useful to be able to run programs on a PC to test them

> Particularly if they make use of file input/output

Page 59: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Labels and Bugs

There is a bug in this program; some characters are interpreted by the label display component as controls for access keys (even though these have no meaning for Smartphone!)

The key of “cheese” gives the output as shown

Page 60: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

TextBox Replacement

Using a TextBox set to read only allows the correct text to be displayed

The read only property of the text box is used to prevent the user changing it

Page 61: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Pocket PC Version

The Pocket PC version is very similar

Just about all of the Smartphone code can be transferred directly over to Pocket PC

Changing the target is very easy

Page 62: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Migrated Code

The Pocket PC has menu keys just like the Smartphone

The program can therefore be used unchanged

Page 63: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Workspaces

You can combine several device projects into a single workspace

The common behaviour (the encoder) has been brought out into a separate project

We will explore this later

Page 64: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Development

You can explore further development of this code:

> Add buttons to the Pocket PC implementation> Store the key in a file on the device> Allow the use of multiple keys> Improve the encoder quality

Page 65: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Advanced DevelopmentOverview

Windows Mobile 5.0 and Casual Games Writing code for Windows Mobile 5.0 Adding compelling features:

> Mobile graphics> Personal Information Management> Messaging> Camera integration

A complete sample game

Page 66: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

What is a Casual Game?

A casual game should be: > quick to play > with you all the time > preferably quick to write

Windows Mobile 5.0 is a great platform to create casual games:

> wide range of mobile platforms> powerful and effective programming tools> gives the security of managed code

Page 67: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Windows Mobile 5.0

Common to all the hardware platforms Provides easy access to underlying device

properties and events:> Device configuration> Camera controls> Direct3D> Outlook PIM information> Messaging and Email> GPS device support

Page 68: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Writing GamesSoftware Deployment

For devices containing phones the service provider may lock the phone

To run an application on a locked phone it must be signed

> Most phones can be unlocked for development

Use the Mobile2Market program to sell your code

Page 69: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Writing GamesCheese Breakout

The basis of the game is to bounce the cheese and hit the tomatoes

The player controls the bread bat and hits the cheese with it:

Sprites> transparency > double buffering> animation

User input> event driven keypad

Page 70: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Bouncing CheeseDrawing the cheese

private void Form1_Paint(object sender, PaintEventArgs e){ e.Graphics.DrawImage(cheeseImage,cx,cy);}

private void timer1_Tick(object sender, EventArgs e){ updatePositions(); Invalidate();}

I use the timer tick method to trigger updates I use the timer tick method to trigger updates

Page 71: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Bouncing CheeseUpdating the cheese position

private void updatePositions(){ cx+=xSpeed; if ( ((cx + cheeseImage.Width) >= this.Width) || (cx <= 0) ) { xSpeed *= -1; }

cy+=ySpeed; if ( ((cy + cheeseImage.Height) >= this.Height) || (cy <= 0) ) { ySpeed *= -1; }}

Page 72: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Moving Cheese

Page 73: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Writing GamesUser Input

The event driven Windows Forms input model lends itself well to games

> Events are fired on key down and key up

However, each platform has some input limitations:> No touchscreen on the Smartphone> Smartphone joypad does not support diagonals

Page 74: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Writing GamesWindows Mobile 5.0 Graphics

You can create 2D graphics using GDI> This is perfect for 2D sprite based games

You can also access the screen directly> But the GAPI interface has been deprecated

For 3D graphics you can use Direct3D:> Some devices have hardware acceleration

Dell Pocket PC Coming soon to Smartphones

Page 75: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Writing GamesStructuring your solutions

Windows Mobile 5.0 programs can run on any of the platforms

But you do need to address control issues> The input mechanisms for Pocket PC and Smartphone are

necessarily different

But you can structure your code to address this

Page 76: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Writing GamesStructuring your solutions

The interfaces isolate the game engine from the particular platform

Smartphone UISmartphone UI Pocket PC UIPocket PC UI Pocket PC Pocket PC Phone UIPhone UI

↑↑↑↑ ↑↑↑↑ Interfaces ↓↓↓↓Interfaces ↓↓↓↓

Underlying Game EngineUnderlying Game Engine

Page 77: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Writing GamesStructuring your solutions : UI

The UI components expose their behaviours by means of an interface

The game engine uses this to drive the display

public interface IBlackJackUI{ void DoRedraw(); void DoSettingBet(); void ShowBets(); void DoStartPlayerHand(); void DoStartDealerHand(); void ShowPlayerBust(); ......}

Page 78: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Writing GamesStructuring your solutions : Game

This is how the UI code views the game engine

It passes user events into the engine which then generates display events in response

public interface IBlackJackGame{ void DoHitPlayer(); void DoNewGame(); void DoPlayerStay(); void DoStartHand(); GameMode Mode { get; } ......}

Page 79: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Writing GamesSolutions and Projects

The solution contains Windows PC and Smartphone games

They both use the same game engine

A Pocket PC version would be very easy to add

Page 80: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Blackjack Game

Page 81: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Writing GamesMultiple Platforms

You can create a single binary which will work on multiple platforms

It can determine the actual dimensions of the target and then scale appropriately

Beware of issues with transparent colors when they are scaled however

Can load multiple versions of game images if required

Page 82: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Writing GamesDiscovering Device Configuration

There are a wide range of platforms and configurations

It is easy to find out what is available on the platform in use

Page 83: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Device propertiesFinding the camera

using Microsoft.WindowsMobile.Status;......

bool hasCamera = Convert.ToBoolean( SystemState.GetValue(SystemProperty.CameraPresent) );

if (hasCamera) { cameraMessageLabel.Text = "Camera Present";}else { cameraMessageLabel.Text = “No Camera";}

Page 84: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Camera Finder

Page 85: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Writing GamesDevice Events

You can also bind your code to events generated when a given property changes

Every event which is managed by the system can be monitored in this way

> Battery: level/power supply> Media: currently playing song > Connectivity: network, phone, cradle

This is very easy to use

Page 86: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Writing GamesBinding to the headset event

using Microsoft.WindowsMobile.Status;......

SystemState headsetState;public HeadsetForm(){ InitializeComponent(); headsetState = new SystemState(SystemProperty.HeadsetPresent); headsetState.Changed += new ChangeEventHandler(headsetState_Changed);}

Page 87: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Writing GamesThe headset event handler

void headsetState_Changed(object sender, ChangeEventArgs args){ bool gotHeadset = Convert.ToBoolean(args.NewValue); if (gotHeadset){ headsetPresentLabel.Text = "Headset Present"; } else{ headsetPresentLabel.Text = "No Headset"; }}

Page 88: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Headset Detector

Page 89: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Compelling FeaturesUsing the Outlook PIM

Windows Mobile 5.0 provides direct access to the Outlook on the mobile device

This was previously achieved using the Pocket Outlook Object Model (POOM) but with Windows Mobile 5.0 this is built in

Making use of contact details and sending messages is now very easy

Page 90: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Using OutlookThe OutlookSession class

OutlookSession outlook = new OutlookSession();

System.Collections.Generic.List<Contact> mobileCcontacts = new System.Collections.Generic.List<Contact>();

void findMobileContacts(){ foreach (Contact c in outlook.Contacts.Items) { if (c.MobileTelephoneNumber != "") { mobileCcontacts.Add(c); } }}

Page 91: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Using OutlookSending an SMS message

SmsMessage sms = new SmsMessage(contact.MobileTelephoneNumber, message);try { sms.Send(); MessageBox.Show("Message Sent OK");}catch { MessageBox.Show("Send Message Failed");}

Page 92: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Addressbook Roulette

Page 93: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Compelling FeaturesIncoming messages

It is very easy to create code which will react to messages when they arrive

In this way you can create games which will act on SMS messages or incoming emails

The event code should be quite familiar

Page 94: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Incoming MessagesBinding to the event

mgot = new MessageInterceptor();mgot.InterceptionAction = InterceptionAction.NotifyAndDelete;mgot.MessageReceived += new MessageInterceptorEventHandler(mgot_MessageReceived);......void mgot_MessageReceived(object sender, MessageInterceptorEventArgs e) { Message mess = e.Message; if ( mess.GetType() == typeof(SmsMessage) ) { SmsMessage sms = mess as SmsMessage; if (sms.Body == "bang") { MessageBox.Show("BANG!"); } }}

Page 95: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Phone Exploder

Page 96: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Compelling FeaturesActing on incoming messages

It is also possible to use an incoming SMS to trigger an application to start up

This is done via the properties of the MessageInterceptor instance that is created

Page 97: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Compelling FeaturesUsing the Camera

If the device has a camera you can use this in your games

You do not have direct control over the device itself > This is to protect user privacy

But you can integrate the use of the camera into games that you write

Page 98: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Using the cameraThe camera dialog

The camera is used in a way directly analogous to a File dialog

It returns the name of the file which contains the picture as taken

You can also configure the camera The actual behaviour of the dialog is platform

dependent

Page 99: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Using the cameraPicture taking method

static public string TakePicture(Form parent){ string result = null; CameraCaptureDialog camera = new CameraCaptureDialog(); camera.Mode = CameraCaptureMode.Still; if (camera.ShowDialog() == DialogResult.OK){ result = camera.FileName; } parent.Show(); camera.Dispose(); return result;}

Page 100: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Using camera imagesPicking Pictures

There is also a SelectPictureDialog This works in exactly the same way as the CameraCaptureDialog

It allows the player to choose a picture It also provides a camera capture option if the

device has a camera For this reason I prefer it

Page 101: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Play with Friends

Page 102: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

The Play With Friends demoGraphical notes

The game has around 20 or so sprites on the screen at any time

> Small sprite class linked to a few images

They are only created once at the start of the program to reduce garbage collection

A backbuffer is used to implement the scrolling background

> Runs at around 20 Hz on the SPV C600

Page 103: Insight Developing for Mobile Devices Rob Miles Department of Computer Science.

Resources

Games Programming with Cheese> Now being upgraded to Windows Mobile 5.0> Search msdn for “Smartphone cheese”

Windows Mobile 5.0 SDK> http://msdn.microsoft.com/mobility/> http://blogs.msdn.com/markprenticems/

All the demos are available for download> http://www.robmiles.com/files