Tuesday, November 24, 2009

Is keyboard / keypad not appearing in wince smart device mobile application for text entry?

Have you wondered why keyboard / keypad not appearing for the textbox if any entry in the mobile device? Dont imagine it will appear automatically.

The solution is quite simple and you will be amazed too.

While running the application in the emulator if there is any text entry it will show as below








but for certain forms the icon  or the key board wont appear like this.




The solution is quite simple ; while adding a new form in the project by default menu1 will appear i think you would have noticed. At any cost dont delete it. Since it plays a major role in showing the keyboard / keypad where ever the textbox appears in the form.

If you delete it unexpectly, then from the toolbox browse for navigation and place the menu control in the form.Thats enough :-) wallaaa the keyboad appears in the form or in the device !!!!!!.



                                       
                                             

You can delete the menu control from the form where ever there is no textbox.

I know the solution would not have satisfied you; the same with me too. Still now i am wondereing what is the conenction between the menu control and the windows mobile form.


Voice recording wince smart device mobile application

Voice recording wince mobile application - While working on mobile projects in most of the scenario there will be a requirement for voice recording at least 75%. I have searched a lot to use dot net compact frameworks dll but i couldn't at last i figured it is not possible using compact frameworks dll.

We can achieve the same thing using pinvoke i.e. Platform Invoke. I will just place the sample code so that you can follow up.

Read this post first before proceeding as you need to know about opennetcf

Code:



create a new form named frmVoice.vb
place button btnstart

 btnstart onclick event
************** START ****************

Private audioRecorder As OpenNETCF.Media.WaveAudio.Recorder
Dim voicefolder As String = "\My Documents\Voice"
Dim voicefile As String = voicefolder + "\Record1.wav"
Const RECORD_DURATION As Integer = 45

 If System.IO.Directory.Exists(voicefolder) = False Then
                System.IO.Directory.CreateDirectory(voicefolder)
            Else
                Dim s As String
                For Each s In System.IO.Directory.GetFiles(voicefolder)
                    System.IO.File.Delete(s)
                Next s
            End If

            Dim fs As FileStream = File.Create(voicefile)
            fs.Close()


            Dim audioStream As System.IO.Stream

            audioStream = System.IO.File.OpenWrite(voicefile)
            audioRecorder = New OpenNETCF.Media.WaveAudio.Recorder

            '---save the audio to stream---
            audioRecorder.RecordFor( _
               audioStream, _
               RECORD_DURATION, _
               OpenNETCF.Media.WaveAudio.SoundFormats.Mono16bit11kHz)



place another button stop
on stop click event

 audioRecorder.Stop()



**************   END   ****************

Reduce Image size wince smart device mobile application

Does any one tried to reduce the size of the image in windows based mobile application using dot net libraries if yes then please post me the URL. but i have figured out an easy way of reducing the image size.

We can use opennetcf's dll's.
About opennetcf :- its a community to develop windows based mobile application.You can find many dlls free to use it in our application.

I just tried with OpenNETCF dll for my image reduce functionality.

Code:
 place the code in any button onclick event



 Dim objImage As System.Drawing.Image
Dim fractionalPercentage As Double
  fractionalPercentage = 20 / 100


 objImage = New Bitmap(FILEPATH)

 Dim bi As OpenNETCF.Drawing.Imaging.IBitmapImage
  bi = OpenNETCF.Drawing.Imaging.ImageUtils.CreateThumbnail( _
                        fsred, New Size(objImage.Width * fractionalPercentage, objImage.Height * fractionalPercentage))




' pctreduced - picture box , the reduced image will be drawn in this control
 pctreduced.Image = _
                           OpenNETCF.Drawing.Imaging.ImageUtils.IBitmapImageToBitmap(bi)

Launch camera programatically in windows mobile wince smart device dot net application

We can launch the camera and capture photos in the windows enabled mobile phone using dot net in built libraries.

You need to import "Microsoft.WindowsMobile.Forms" libraries which can be found when you install "Windows Mobile 6 SDK" under the folder "Windows Mobile 6 SDK\Managed Libraries".

The copy the below code in any button event.

 Dim cameraimgfolder As String = "\My Documents\pictures"
Dim objImage As System.Drawing.Image
Dim MycameraDialog As New CameraCaptureDialog()

MycameraDialog .Owner = Me
MycameraDialog .Title = "Take Still Picture"

MycameraDialog .Mode = CameraCaptureMode.Still
MycameraDialog .StillQuality = CameraCaptureStillQuality.Normal
MycameraDialog .InitialDirectory = cameraimgfolder


If ((MycameraDialog .ShowDialog() <> DialogResult.OK) _
                Or (MycameraDialog .FileName = "")) Then
                ' Handle the cancel case here.

    MycameraDialog .DefaultFileName = "XXXXX"
    MycameraDialog .InitialDirectory = cameraimgfolder
End If

' we need to know the file name as it will be created automatically
TextBox3.Text = cameraDialog.FileName

filePath = TextBox3.Text
Dim picturenamearr() As String
picturenamearr = filePath.Split("\")
filename = picturenamearr.Last


If TextBox3.Text.Trim <> "" Then
 'storing in image object; so that you can place the object in the picture box if you need
 objImage = New Bitmap(TextBox3.Text.ToString)

End If

Notes:
After the image has been captured based on the device it will automatically jumps to the initiated screen or else it will show you back button.

Monday, November 23, 2009

Get mobile number of a sim card - wince smart device mobile application dot net

At any cost there is no possible way to get the mobile number because the mobile number is just the ID given to the sim number. so the network operator can identify you with help of sim number only and not with the mobile number.

Think of a table structure

Primarykey                                      value
your sim number                              your mobile number
357533000961259                        +91XXXXXXXXXX


:-( :-( :-( :-(

Other blogs
Blog Blog

Get IMEI IMSI number of the mobile phone - wince smart device mobile application

Have you wondered how to fetch the IMEI or IMSI number from the winows enabled mobile phone through dot net!!!

Yes there is a solution. I dont know from where i have found out the code , definitely the credit goes to the author.


create a class file named "DevicePhoneInfo.vb"

********************* START **************************************

Imports System

Imports System.Drawing
Imports System.Collections
Imports System.Windows.Forms
Imports System.Data
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Xml
Imports System.IO

Namespace TAPI
Public Module PhoneInfo
'Private Sub New()
'End Sub
'original code location:
'http://www.developersdex.com/vb/message.asp?p=2916&ID=%3C68D1F07B-ECB0-4A15-AFCA-2A911FC3234C%40microsoft.com%3E
Public Sub [Get](ByRef manufacturer As String, ByRef model As String, ByRef revision As String, ByRef serialNumber As String, ByRef subsciberId As String)
Dim hLine As IntPtr
Dim dwNumDev As Integer
Dim num1 As Integer = &H20000
Dim lineInitializeParams As New LINEINITIALIZEEXPARAMS()
lineInitializeParams.dwTotalSize = CUInt(Marshal.SizeOf(lineInitializeParams))
lineInitializeParams.dwNeededSize = lineInitializeParams.dwTotalSize
lineInitializeParams.dwOptions = 2
lineInitializeParams.hEvent = IntPtr.Zero
lineInitializeParams.hCompletionPort = IntPtr.Zero
'#Region "lineInitializeEx"
Dim result As Integer = Tapi.lineInitializeEx(hLine, IntPtr.Zero, IntPtr.Zero, Nothing, dwNumDev, num1, _
lineInitializeParams)
If result <> 0 Then
Throw New ApplicationException(String.Format("lineInitializeEx failed!" & vbLf & vbLf & "Error Code:{0}", result.ToString()))
End If
'#End Region
'#Region "lineNegotiateAPIVerison"
Dim version As Integer
Dim dwAPIVersionLow As Integer = &H10004
Dim dwAPIVersionHigh As Integer = &H20000
Dim lineExtensionID As LINEEXTENSIONID
result = Tapi.lineNegotiateAPIVersion(hLine, 0, dwAPIVersionLow, dwAPIVersionHigh, version, lineExtensionID)
If result <> 0 Then
Throw New ApplicationException(String.Format("lineNegotiateAPIVersion failed!" & vbLf & vbLf & "Error Code: {0}", result.ToString()))
End If
'#End Region

'#Region "lineOpen"
Dim hLine2 As IntPtr = IntPtr.Zero
result = Tapi.lineOpen(hLine, 0, hLine2, version, 0, IntPtr.Zero, _
&H2, &H4, IntPtr.Zero)
If result <> 0 Then
Throw New ApplicationException(String.Format("lineNegotiateAPIVersion failed!" & vbLf & vbLf & "Error Code: {0}", result.ToString()))
End If
'#End Region

'#Region "lineGetGeneralInfo"
Dim structSize As Integer = Marshal.SizeOf(New LINEGENERALINFO())
Dim bytes As Byte() = New Byte(structSize - 1) {}
Dim tmpBytes As Byte() = BitConverter.GetBytes(structSize)

For index As Integer = 0 To tmpBytes.Length - 1
bytes(index) = tmpBytes(index)
Next
'#End Region

'#Region "make initial query to retrieve necessary size"
result = Tapi.lineGetGeneralInfo(hLine2, bytes)

' get the needed size
Dim neededSize As Integer = BitConverter.ToInt32(bytes, 4)

' resize the array
bytes = New Byte(neededSize - 1) {}

' write out the new allocated size to the byte stream
tmpBytes = BitConverter.GetBytes(neededSize)
For index As Integer = 0 To tmpBytes.Length - 1
bytes(index) = tmpBytes(index)
Next

' fetch the information with properly size buffer
result = Tapi.lineGetGeneralInfo(hLine2, bytes)

If result <> 0 Then
Throw New ApplicationException(Marshal.GetLastWin32Error().ToString())
End If

'#End Region

'#Region "actual data fetching"
Dim size As Integer
Dim offset As Integer

' manufacture
size = BitConverter.ToInt32(bytes, 12)
offset = BitConverter.ToInt32(bytes, 16)
manufacturer = Encoding.Unicode.GetString(bytes, offset, size)
manufacturer = manufacturer.Substring(0, manufacturer.IndexOf(ControlChars.NullChar))

' model
size = BitConverter.ToInt32(bytes, 20)
offset = BitConverter.ToInt32(bytes, 24)
model = Encoding.Unicode.GetString(bytes, offset, size)
model = model.Substring(0, model.IndexOf(ControlChars.NullChar))

' revision
size = BitConverter.ToInt32(bytes, 28)
offset = BitConverter.ToInt32(bytes, 32)
revision = Encoding.Unicode.GetString(bytes, offset, size)
revision = revision.Substring(0, revision.IndexOf(ControlChars.NullChar))

' serial number
size = BitConverter.ToInt32(bytes, 36)
offset = BitConverter.ToInt32(bytes, 40)
serialNumber = Encoding.Unicode.GetString(bytes, offset, size)
serialNumber = serialNumber.Substring(0, serialNumber.IndexOf(ControlChars.NullChar))

' subscriber id
size = BitConverter.ToInt32(bytes, 44)
offset = BitConverter.ToInt32(bytes, 48)
subsciberId = Encoding.Unicode.GetString(bytes, offset, size)
subsciberId = subsciberId.Substring(0, subsciberId.IndexOf(ControlChars.NullChar))

'#End Region


'tear down
Tapi.lineClose(hLine2)

Tapi.lineShutdown(hLine)
End Sub
End Module

End Namespace
 
********************* END ****************************************
 
create another class named "TAPI.vb"
 
********************* START **************************************
 
  Imports System

Imports System.Drawing
Imports System.Collections
Imports System.Windows.Forms
Imports System.Data
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Xml
Imports System.IO

Namespace TAPI
Public Module PhoneInfo
'Private Sub New()
'End Sub
'original code location:
'http://www.developersdex.com/vb/message.asp?p=2916&ID=%3C68D1F07B-ECB0-4A15-AFCA-2A911FC3234C%40microsoft.com%3E
Public Sub [Get](ByRef manufacturer As String, ByRef model As String, ByRef revision As String, ByRef serialNumber As String, ByRef subsciberId As String)
Dim hLine As IntPtr
Dim dwNumDev As Integer
Dim num1 As Integer = &H20000
Dim lineInitializeParams As New LINEINITIALIZEEXPARAMS()
lineInitializeParams.dwTotalSize = CUInt(Marshal.SizeOf(lineInitializeParams))
lineInitializeParams.dwNeededSize = lineInitializeParams.dwTotalSize
lineInitializeParams.dwOptions = 2
lineInitializeParams.hEvent = IntPtr.Zero
lineInitializeParams.hCompletionPort = IntPtr.Zero
'#Region "lineInitializeEx"
Dim result As Integer = Tapi.lineInitializeEx(hLine, IntPtr.Zero, IntPtr.Zero, Nothing, dwNumDev, num1, _
lineInitializeParams)
If result <> 0 Then
Throw New ApplicationException(String.Format("lineInitializeEx failed!" & vbLf & vbLf & "Error Code:{0}", result.ToString()))
End If
'#End Region
'#Region "lineNegotiateAPIVerison"
Dim version As Integer
Dim dwAPIVersionLow As Integer = &H10004
Dim dwAPIVersionHigh As Integer = &H20000
Dim lineExtensionID As LINEEXTENSIONID
result = Tapi.lineNegotiateAPIVersion(hLine, 0, dwAPIVersionLow, dwAPIVersionHigh, version, lineExtensionID)
If result <> 0 Then
Throw New ApplicationException(String.Format("lineNegotiateAPIVersion failed!" & vbLf & vbLf & "Error Code: {0}", result.ToString()))
End If
'#End Region

'#Region "lineOpen"
Dim hLine2 As IntPtr = IntPtr.Zero
result = Tapi.lineOpen(hLine, 0, hLine2, version, 0, IntPtr.Zero, _
&H2, &H4, IntPtr.Zero)
If result <> 0 Then
Throw New ApplicationException(String.Format("lineNegotiateAPIVersion failed!" & vbLf & vbLf & "Error Code: {0}", result.ToString()))
End If
'#End Region

'#Region "lineGetGeneralInfo"
Dim structSize As Integer = Marshal.SizeOf(New LINEGENERALINFO())
Dim bytes As Byte() = New Byte(structSize - 1) {}
Dim tmpBytes As Byte() = BitConverter.GetBytes(structSize)

For index As Integer = 0 To tmpBytes.Length - 1
bytes(index) = tmpBytes(index)
Next
'#End Region

'#Region "make initial query to retrieve necessary size"
result = Tapi.lineGetGeneralInfo(hLine2, bytes)

' get the needed size
Dim neededSize As Integer = BitConverter.ToInt32(bytes, 4)

' resize the array
bytes = New Byte(neededSize - 1) {}

' write out the new allocated size to the byte stream
tmpBytes = BitConverter.GetBytes(neededSize)
For index As Integer = 0 To tmpBytes.Length - 1
bytes(index) = tmpBytes(index)
Next

' fetch the information with properly size buffer
result = Tapi.lineGetGeneralInfo(hLine2, bytes)

If result <> 0 Then
Throw New ApplicationException(Marshal.GetLastWin32Error().ToString())
End If

'#End Region

'#Region "actual data fetching"
Dim size As Integer
Dim offset As Integer

' manufacture
size = BitConverter.ToInt32(bytes, 12)
offset = BitConverter.ToInt32(bytes, 16)
manufacturer = Encoding.Unicode.GetString(bytes, offset, size)
manufacturer = manufacturer.Substring(0, manufacturer.IndexOf(ControlChars.NullChar))

' model
size = BitConverter.ToInt32(bytes, 20)
offset = BitConverter.ToInt32(bytes, 24)
model = Encoding.Unicode.GetString(bytes, offset, size)
model = model.Substring(0, model.IndexOf(ControlChars.NullChar))

' revision
size = BitConverter.ToInt32(bytes, 28)
offset = BitConverter.ToInt32(bytes, 32)
revision = Encoding.Unicode.GetString(bytes, offset, size)
revision = revision.Substring(0, revision.IndexOf(ControlChars.NullChar))

' serial number
size = BitConverter.ToInt32(bytes, 36)
offset = BitConverter.ToInt32(bytes, 40)
serialNumber = Encoding.Unicode.GetString(bytes, offset, size)
serialNumber = serialNumber.Substring(0, serialNumber.IndexOf(ControlChars.NullChar))

' subscriber id
size = BitConverter.ToInt32(bytes, 44)
offset = BitConverter.ToInt32(bytes, 48)
subsciberId = Encoding.Unicode.GetString(bytes, offset, size)
subsciberId = subsciberId.Substring(0, subsciberId.IndexOf(ControlChars.NullChar))

'#End Region


'tear down
Tapi.lineClose(hLine2)

Tapi.lineShutdown(hLine)
End Sub
End Module

End Namespace
 
********************* END **************************************

create a form named "getIMEI_IMSI.vb"  , in the code behind  paste the following code

*********************  START  **************************************
Imports System


Imports System.Collections.Generic

Imports System.ComponentModel

Imports System.Data

Imports System.Drawing

Imports System.Text

Imports System.Windows.Forms

Imports Camera2.TAPI



Public Class getIMEI_IMSI



Private Sub getIMEI_IMSI_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load



End Sub



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim manifactrer As String

Dim model As String

Dim revision As String

Dim imsi As String

Dim imei As String



PhoneInfo.[Get](manifactrer, model, revision, imei, imsi)



TextBox1.Text = imsi



TextBox2.Text = imei

End Sub

End Class
 
********************* END **************************************

Saturday, November 21, 2009

Running/Debugging the wince smart device mobile application

Running the application require certain additional efforts than the regular vb.net application.

Pre-requiste / pre- requirement to run the application:

1. Active sync - Most important software to be installed in the machine.
2. Mobile phone emulators.

Mobile phone emulators

Some words about Mobile phone emulators  Emulators(Someone who copies the words or behaviour of another)  are nothing but the simulation of real mobile phone as a software. so that the mobile application can be tested against the software instad of real mobile phone.

Most of the mobile vendor provide emulators as free download to develop the applications.

No need to worry as dot net itself has some pre-loaded emulators.

Active Sync

Some words about  Active Sync  -  As the name suggests active sync ; syncs the  real moble/emulator against the computer/system.

It act as a communication bridge between the mobile phone (emulator/real) and the system.


Running the application

Below shown are the list of images; follow in the same order then you will have no problem in running the application.


Step:1  Design the form as i shown below in the wince environment



Step2: Go to Tools -> Device emulator manager; where it will list all the emulators installed in your machine.



Step 3: Choose any emulator say "POCKET PC 2003" ; you can choose any emulators and it depends on the aplplication you develop. As far as testing consideration we can choose any device only the layout i.e. height and width of the screen is going to be get changed. As shown below right click the selected emulator and choose "connect"



Step4: The icon will be changed as play icon as shown below.



Step 5: Now again select the emulator right click and choose cradle ; the icon will be changed .Dont forget to note down the icon in the taskbar i.e Active sync icon will be start rotating which means it is getting connected. It will take sometime to get connected. Active sync must be installed.



Step 6: Now from the dot net enviorment press f5 i.e. run the aplication following screen will be shown to you. Choose the emulator that you have already selected in the device emulator manager and click deploy. It will take some time to deploy.


 


Step 7: The form will be loaded inside the mobile emulator. Now you can work in the mobile by doing actions using the mobile buttons.


 



The final image will be shown when u run the application. if you need the break point to be hit then place the breakpoint some where in the code then it appear as we see during runing the ordinary aplications.

Creating wince smart device desktop Mobile application

Hello everyone this is my first article on the internet. As i am little bit comfortable with mobile application specificaaly in dot net i decided to share some of the information with the public.

During my learning statge i have struggled how to create a mobile project but after spending consider time with the net with huge support from google ( as most of the programmers do :-) lol ) i came with what we can do and not.

Pictures and code comments are mostly out of framework 3.5

As a first article i have decided to publish how to create a wince mobile project

The first step will be choosing a right project from the set of available option. My pictures will explain you better than me.




The second step will be choosing the device based framework. You need to know what is your mobile device framework so that you can develop right application for your device.  My mobile has Win ce framework so my samples will be made out of wince.



The final step will be the form will be shown to you with the screen same as vb.net but the screen size will be considerably smaller.