Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Using the Smart Device Framework for Windows Mobile Development : Page 2

The .NET Compact Framework's class libraries are sadly inadequate for developing full-featured Windows Mobile applications, sometimes forcing you to rely upon the problemtatic Platform Invoke. Enter Smart Device Framework (SDF), a group of extensions designed to pick up where the Compact Framework's class libraries leave off.




Application Security Testing: An Integral Part of DevOps

Recording Sound
The ability to record sound is very useful in situations where you need to say, record a phone conversation. To use the sound recording capability in the SDF, add a reference to the OpenNETCF.dll library in your project. Declare the following variables:

'---for audio recording--- Private audioRecorder As OpenNETCF.Media.WaveAudio.Recorder '---duration to record (in seconds)--- Const RECORD_DURATION As Integer = 10000

To record voice, first open a file for voice recording and then use the RecordFor() method available in the Recorder class:

'---save the recording to storage--- Dim audioStream As IO.Stream audioStream = System.IO.File.OpenWrite("\My Documents\Record1.wav") audioRecorder = New OpenNETCF.Media.WaveAudio.Recorder '---save the audio to stream--- audioRecorder.RecordFor( _ audioStream, _ RECORD_DURATION, _ OpenNETCF.Media.WaveAudio.SoundFormats.Mono16bit11kHz)

The OpenNETCF.Media.WaveAudio.SoundFormats enumerations contain the various sound qualities that you can use for recording. Also, you can specify the duration of the recording via the second parameter (in seconds). Alternatively, to stop the recording prematurely simply call the Stop() method:

'---stop recording--- audioRecorder.Stop()

Once you have finished recording, you'll be able to find the Record1.wav file stored in the \My Documents\ folder (see Figure 1).

Figure 1. Record1.wav: Locating the sound file.

Vibrating Your Windows Mobile Device
Almost all devices sold in the market today supports silent alert (by spinning a miniature motor inside the device, thereby vibrating the phone). Unfortunately, the .NET Compact Framework does not provide any library for you to vibrate your phone.

For this purpose, you can use the OpenNETCF.WindowsMobile.dll library. If you are using a Windows Mobile 6 Standard device (a.k.a Smartphone), use the Play() method in the Vibrate class to vibrate your phone:


To stop the vibration, use the Stop() method:


Unfortunately, the above lines of code do not work for Pocket PC devices (now known as Windows Mobile 6 Professional and Classic devices). For Pocket PCs, you need to use the OpenNETCF.WindowsCE.dll library. You will use the notification led to emulate vibration.

The following code shows how to cause your Pocket PC to vibrate for half a second:

Dim vib As New OpenNETCF.WindowsCE.Notification.Led '---start vibration--- vib.SetLedStatus(1, OpenNETCF.WindowsCE.Notification.Led.LedState.On) System.Threading.Thread.Sleep(500) '---stop vibration--- vib.SetLedStatus(1, _ OpenNETCF.WindowsCE.Notification.Led.LedState.Off)

The first parameter of the SetLedStatus() method takes in an integer representing the led number. You may need to trial-and-error to find the number that works correctly on your device.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date