With mobile development one can build many types of application with .Net. Just like the desktop and laptop world these applications can be broken down into two types of applications WinForms or Web based. A lot of the entries on the blog are about the Compact Framework, so what about the web. This entry looks at web development with ASP.Net 3.5 and Visual Studio 2008.
In web based development, Mobile Internet Explorer will be used to fetch pages from a web server. While the pages can be HTML or cHTML ASP.Net is used to dynamically build the content that is sent. In Visual Studio 2008 the Mobile Controls have been removed. The current direction is to treat Mobile IE no differently than say FireFox, IE or Opera. This also means that it is possible to build AJAX based pages to run on Mobile IE.
Building mobile websites is no different than building a regular website. In fact, by modifying the browser file existing web sites can be mobile enabled. However, this is not recommended since there are real differences between a small pocket computer and a laptop or desktop. While some people and companies think that the Internet is no different on a phone physics still exist. So for example, the NY Times home page can be loaded and read on a Windows Mobile device. The page is very large and requires megabytes of bandwidth to display rapidly even on 3G networks. And it really is not a good experience even with other phones.
So the first step is to get ASP.Net to recognize that it is talking to a phone. And then it can adapt to itself to the device rather than have the user adapt. So launch VS2008 if you haven’t already. Next select File|New|Web Site… and you should see the New Web Site dialog box. Make sure you have ASP.NET Web Site highlighted and set the location.
Then hit OK and you should be rewarded with a Web Site solution.
Hitting run yields a blank page in the computer’s web browser. To see the blank page in a device there are a couple of choices:
- Load an emulator
- Attach a physical device
- Use a device with WiFi
- Expose the site to the Internet and use a device via a cellular network connection
Load an Emulator
The easiest thing to use during initial testing is the emulator. VS2008 comes with a device emulator that allows testing various versions of Windows Mobile including Pocket PC 2003, Smartphone 2003, Windows Mobile 5.0 Pocket PC, Windows Mobile 5.0 Smartphone, Windows Mobile 6.0 Standard, and Windows Mobile 6.0 Professional. To access the emulators go to Tools|Device Emulator Manager… which is version 3 of Microsoft’s emulators. From the Manager pick the device you wish to test by selecting it and clicking Action|Connect.
With the emulator to be tested selected click the right mouse to bring up the context menu and select cradle. This will cause the computer to think a device is now cradled and ActiveSync in older OSes or Windows Mobile Device Center in Vista to setup a connection. If a connection is not made make sure that DMA (Direct Memory Access) is setup in ActiveSync.
If everything is correct the Device Emulator Manager will show the cradled symbol by the emulator being used. Next in the emulator launch Mobile IE and type in the IP address of the development computer and IP port along with the path to the default page. A blank page should be displayed in the emulator.
Physical Device
With a physical device testing is a little harder. Mostly it is due to making sure the device can access the web site. The easiest way is to cradle the device similar to the emulator. The other ways are to expose the web site to the network either private or public networks. If the device has WiFi by putting it on the same network as the development computer it should be able to access the web site. Using WiFi the device will connect via an Access Point.
To use the cellular network requires that the website must be accessible via the Internet. Setting up a website is beyond the scope of this book. Please refer to a network book and the manuals for the equipment used to access the Internet.
Detecting Mobile IE
First step is to create the page and display the browser information. This will give a useful tool to understand the browser capabilities. Set the title to the page as “Browser”. In between the DIV do the following:< /p>
- Text – “The browser is a “
- Add a label
- Name – BrowserType
- Text – Browser
Next add a page load event to update the BrowserType label with the browser client using
BrowserType.Text = Request.Browser.Browser;
Now run the page on the computer and Windows Mobile IE. You will get to different browser strings with the Windows Mobile showing up as for example WinCE 6.0. This is important so that a web site can be customized to device. Adding a list to fill with RequestHeaders will give additional information. This can be accomplished by adding a ListBox named Capabilities. And the following in the page load event
Capabilities.Rows = Request.Headers.Count;
for(int loop=0; loop < Request.Headers.Count; loop++)
{
Capabilities.Items.Add(string.Format("{0} {1}",
Request.Headers.GetKey(loop),
Request.Headers.Get(loop)));
}
Running the new page gives the following output to the emulator.
A couple of key items can be found in the header information, UA-color and UA-pixels. UA-color tells the available color palette that can be displayed by the device in this case 16 bit color. UA-pixels gives the screen resolution in this case 240 pixels wide by 320 pixels tall. Between the two enough information is available to build screens that fit.
This is nice explanation about .net3.0 and mobile applications
Posted by: praveen | January 09, 2008 at 01:20 AM