Development of Windows Mobile Applications (Part 2)

Exclusive offer: get 50% off this eBook here
FreePBX 2.5 Powerful Telephony Solutions

FreePBX 2.5 Powerful Telephony Solutions — Save 50%

Configure, deploy, and maintain an enterprise-class VoIP PBX

$23.99    $12.00
by Prashant Thakkar | September 2009 | .NET Microsoft

Read Part One of Development of Windows Mobile Applications here.

Now let us see how to deploy it on Windows Mobile Device. For deploying the application on device you need to have ActiveSync installed.

There are two ways in which application can be deployed on to the device.  First option is to connect the device to the Development machine via USB. ActiveSync will automatically detect it and you can click on FreePBX 2.5 Powerful Telephony Solutions on the top bar. And this time select option "Windows Mobile 6 Professional Device".

FreePBX 2.5 Powerful Telephony Solutions

But then this approach is useful when you want to test/deploy and use the application yourself. What if you want to distribute it to others? In that case you need to create an installation program for your Windows mobile application. The installation file in the Windows Mobile world is distributed in the form of a CAB file. So once we have done with application we should opt for option 2 of creating a CAB file (A CAB file is a library of compressed files stored as a single file).

Creating CAB File

Creating a CAB file itself is a new project. To create CAB project right click on the solution and select the option New Project as shown below.

FreePBX 2.5 Powerful Telephony Solutions

Clicking on New Project option will open Add New Project Wizard. Select option Setup and Deployment under Other Project Types on the left hand menu. Then select option Smart Device CAB Project on right hand side as shown below. We have named this project as MyFirstAppCAB.

FreePBX 2.5 Powerful Telephony Solutions

Click OK and MyFirstAppCAB project is created under the solution a shown.

FreePBX 2.5 Powerful Telephony Solutions

Now to add files to the CAB, right click on the Application Folder under File System on Target Machine and select option Add-> Project Output as shown.

FreePBX 2.5 Powerful Telephony Solutions

On selecting Project Output option, the following screen will popup. Depending upon the requirement, select what all needs to be compressed in CAB file. For this example we require only output, hence will select option Primary output.

FreePBX 2.5 Powerful Telephony Solutions

Now right click on CAB project MyFirstAppCAB and select option Build.

FreePBX 2.5 Powerful Telephony Solutions

CAB file with name MyFirstAppCAB will be created at the location MyFirstAppMyFirstAppCABDebug.

Now let us see how we can deploy this CAB file on emulator and run the application. Click on Tools on the top bar and select option Device Emulator Manager.

FreePBX 2.5 Powerful Telephony Solutions

This will open a Device Emulator Manager as shown below. Select option Windows Mobile 6 Classic Emulator. Right click and select option Connect.

FreePBX 2.5 Powerful Telephony Solutions

Windows Mobile Emulator will start and on Device Emulator Manager you can see FreePBX 2.5 Powerful Telephony Solutions to left of Windows Mobile 6 Classic Emulator as shown below.

FreePBX 2.5 Powerful Telephony Solutions

Next step is to Cradle.

If you are attempting to cradle for the 1st time, then you need to setup ActiveSync. To setup ActiveSync, double click on FreePBX 2.5 Powerful Telephony Solutions on right bottom on Task bar. Microsoft ActiveSync will open up, select option File -> Connection Settings as shown in figure below.

FreePBX 2.5 Powerful Telephony Solutions

Connection Settings window will be open up as shown below. Check the option Allow Connections to one of the followings and then from the drop down select the option DMA.

FreePBX 2.5 Powerful Telephony Solutions

After connecting Windows Mobile 6 Classic Emulator using Device Emulator Manager, again right click and select option Cradle as shown below. Cradle will start ActiveSync and make Emulator work as device connected using ActiveSync.

FreePBX 2.5 Powerful Telephony Solutions

On successful connection you can see FreePBX 2.5 Powerful Telephony Solutions on the left of option Windows Mobile 6 Classic Emulator on Device Emulator Manager as shown.

FreePBX 2.5 Powerful Telephony Solutions

FreePBX 2.5 Powerful Telephony Solutions Configure, deploy, and maintain an enterprise-class VoIP PBX
Published: August 2009
eBook Price: $23.99
Book Price: $39.99
See more
Select your format and quantity:

Open Microsoft ActiveSync and click on Explore.

FreePBX 2.5 Powerful Telephony Solutions

This will open Mobile Device. Select My Windows Mobile-Based Device->Program Files and copy CAB file. On the Emulator, click on Start->Programs->File Explorer as shown below.

FreePBX 2.5 Powerful Telephony Solutions

On File Explorer, if the View is My Documents then click on arrow next to it and select My Device option as shown below.

FreePBX 2.5 Powerful Telephony Solutions

Program Files is the folder in which we had copied the CAB file so browse through Program Files and click on MyFirstAppCAB.

FreePBX 2.5 Powerful Telephony Solutions

Successful installation of CAB file will create folder MyFirstAppCAB. Browse through the folder and click MyFirstApp to execute our Hello World Application.

FreePBX 2.5 Powerful Telephony Solutions

After Hello World let us quickly try and develop another application which will fetch and display Quotes of the Day from internet via RSS feed on button click. We will fetch RSS feed from http://feeds.feedburner.com/brainyquote/QUOTEBR.

Create a new Project and let us name it as QuotesOfTheDay. Name the form as QuotesOfTheDayForm and set Caption as Quotes Of The Day. From Toolbox drag and drop a button on the form, name the button as btnShowQuotes and set label on the button as Show Quotes. Similarly add one more button, name it as btnClear and set label on the button as Clear.

Click on Show Quotes, will invoke http://feeds.feedburner.com/brainyquote/QUOTEBR and fetch the RSS feed, process it.

To show the list of Quotes for the day we will use TextBox. So drag and drop TextBox from ToolBox.  Name TextBox as tbQuotes. By default TextBox allows single line to be entered or displayed. Here we can get multiple Quotes, so set Multiline property as True. Beside TextBox is editable by default, so make it read only by making ReadOnly property as True as shown below.

FreePBX 2.5 Powerful Telephony Solutions

Similarly click on Clear, will clear the TextBox.

Let us look at the complete source code. And understand how we invoke RSS feed, process the response and display it.

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;
using System.Xml;


namespace QuotesOfTheDay
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btnShowQuotes_Click(object sender, EventArgs e)
{
// URL of RSS Feed for Quotes of the Day
String urlStr = "http://feeds.feedburner.com/brainyquote/QUOTEBR";
try
{
// Set Cursor to Wait Cursor
Cursor.Current = Cursors.WaitCursor;

// Create HttpWebRequest to invoke RSS feed URL.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlStr);
// Get response for the request.
HttpWebResponse responese = (HttpWebResponse)request.GetResponse();

// Check response.
if (responese.StatusCode.ToString().Equals("OK"))
{
// Get Response Stream and convert it StreamReader.
StreamReader responseStream = new StreamReader(responese.GetResponseStream());

// Read entire content from StreamReader
String responesStr = responseStream.ReadToEnd();

// RSS feed returned represents an XML. To extract data from RSS feed, create
XMLDocumnet and Load the XML with the response.
XmlDocument rssFeedXML = new XmlDocument();
rssFeedXML.LoadXml(responesStr);

StringBuilder _quotes = new StringBuilder();
int lineNumber = 1;

// Iterate through all "item" nodes of the RSS feed XML.
foreach (XmlNode item in rssFeedXML.DocumentElement.SelectNodes("channel/item"))
{
// Extract title.
String title = item.SelectSingleNode("title").InnerText;

// Extract description.
String description = item.SelectSingleNode("description").InnerText;

// Format and Append Count and title and description.
_quotes.Append(lineNumber + ". " + title + ": " + description + "rn");

// Increment lineNumber by 1
lineNumber++;

}
// Set Cursor to Default Cursor
Cursor.Current = Cursors.Default;
// Assign content of _quotes StringBuilder to TextBox tbQuotes.
tbQuotes.Text = _quotes.ToString();
}
else
{
// Set Cursor to Default Cursor
Cursor.Current = Cursors.Default;
MessageBox.Show("Response Status Code: " + responese.StatusCode
+ " Description: " + responese.StatusDescription);
}

// Close HttpWebResponse
responese.Close();
}
catch (Exception exception)
{
// Set Cursor to Default Cursor
Cursor.Current = Cursors.Default;
MessageBox.Show("Error while accessing " + urlStr);
}
}

private void btnClear_Click(object sender, EventArgs e)
{
// To clear TextBox we will assign and empty string.
tbQuotes.Text = "";
}
}
}

The entire code of invoking, processing and displaying quotes is in the method btnShowQuotes_Click.

Key Steps:

  1. Create HttpWebRequest for the URL.
  2. Get Response, for the request.
  3. Check whether response is OK. This indicate that response to the request  made to the server was ok and server was able to respond to it.
  4. If response is OK, then read the response string in this case XML string from the response stream.
  5. Now Process the response. Since we know it is an XML so we will convert the response string into XML Document.
  6. Iterate through the child node item. Fetch title and description. Format and append it using StringBuilder. Assign content in StringBuilder to TextBox.

Now deploy and run to see the output as below.

Depending upon the way form is designed, output may vary.

FreePBX 2.5 Powerful Telephony Solutions

Click on Show Quotes to fetch quote of the day. Ensure Internet Connection available.

FreePBX 2.5 Powerful Telephony Solutions

Click on Clear to clear TextBox.

With this, we conclude our article of taking your first steps in Windows Mobile development.

Summary

Thus we saw the entire development cycle (code, test, deploy) of Windows Mobile applications. This article covered two applications, "Hello World" which helped us to understand basics of Windows Mobile 6.0 Development, while "Quotes of the Day" was a step ahead, where we learnt fetching and displaying data from the Internet. This article should serve as a launch pad for your Windows Mobile Application development journey.

 

If you have read this article you may be interested to view :

Asterisk 1.4 – the Professional’s Guide Implementing, Administering, and Consulting on Commercial IP Telephony Solutions
Published: August 2009
eBook Price: $26.99
Book Price: $44.99
See more
Select your format and quantity:

About the Author :


Prashant Thakkar is Currently working as Senior Software Engineer at Xoriant Solution, Mumbai. He has over five years of experience of working on Java and Window Mobile Development. He can be contacted by email at prashant.thakkar@xoriant.com. Prashant is also active on Twitter, you can follow him at "ppandhi".

Books From Packt

Software Testing with Visual Studio Team System 2008
Software Testing with Visual Studio Team System 2008

ASP.NET 3.5 CMS Development
ASP.NET 3.5 CMS Development

ASP.NET 3.5 Social Networking
ASP.NET 3.5 Social Networking

Drools JBoss Rules 5.0 Developer's Guide
Drools JBoss Rules 5.0 Developer's Guide

Pentaho Reporting 3.5 for Java Developers
Pentaho Reporting 3.5 for Java Developers

Building Enterprise Ready Telephony Systems with sipXecs 4.0
Building Enterprise Ready Telephony Systems with sipXecs 4.0

Microsoft Visual C++ Windows Applications by Example
Microsoft Visual C++ Windows Applications by Example

C# 2008 and 2005 Threaded Programming: Beginner's Guide
C# 2008 and 2005 Threaded Programming: Beginner's Guide

 

No votes yet
build error! by
exception of type 'System.Net.WebException' occurred in System.dll

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
9
a
T
N
X
2
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software