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


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.

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, _
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---
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)

        '---stop vibration---
        vib.SetLedStatus(1, _

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.

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