Post on 14-Dec-2015
New Managed Messaging, New Managed Messaging, State, And Notification State, And Notification APIs In Windows Mobile APIs In Windows Mobile 20052005
Gaurav KhannaGaurav Khannagkhanna@microsoft.comgkhanna@microsoft.comDeveloper EvangelistDeveloper EvangelistMicrosoft IndiaMicrosoft India
MManagementanagementTToolsools
CCommunicationsommunications& & MMessagingessaging
Device Update Agent
Software Update Services
Live Communications Server
Exchange Server
Internet Security and Acceleration Server
Speech Server
Image Update
LLocation ocation SServiceservices
MMultimediaultimedia
MapPoint
DirectX
Windows Media
Visual Studio 2005DDevelopment evelopment TToolsools
MFC 8.0, ATL 8.0
Win32NNativeative
MManagedanaged
SServer erver SSideide
LLightweightightweight
RRelationalelationalSQL Server 2005 Express EditionEDB
DDa
taata
PPro
gra
mm
ing
ro
gra
mm
ing
MM
od
el
od
el
DDevice evice BBuilding uilding TToolsools
HHardware/ardware/DDriversrivers
Windows XP DDK
Windows Embedded Studio
Platform Builder
OEM/IHV SuppliedBSP
(ARM, SH4, MIPS)OEM Hardware and Standard Drivers
Standard PC Hardware and Drivers
SQL Server 2005SQL Server 2005 Mobile Edition
ASP.NET Mobile Controls ASP.NET
.NET Compact Framework .NET Framework
Microsoft Operations Manager
Systems Management Server
Here’s What We’ll CoverHere’s What We’ll Cover
Lots of Brand New Managed APIsLots of Brand New Managed APIsOnly for Windows Mobile 5.0Only for Windows Mobile 5.0
.NET Compact Framework 1.0 or 2.0.NET Compact Framework 1.0 or 2.0
CapabilitiesCapabilities
UsageUsage
Common mistakesCommon mistakes
Lots of code snippetsLots of code snippets
Initiate Calls With Phone.TalkInitiate Calls With Phone.Talk
Get properties and events through theGet properties and events through theState & Notification BrokerState & Notification Broker
Dim phone As New Phonephone.Talk( “425-555-1212” )
Let’s TalkLet’s Talk
Microsoft.WindowsMobileMicrosoft.WindowsMobileNamespace SummaryNamespace SummaryWindowsMobile.PocketOutlook
Edit Contacts, Appointments, and TasksControl the Messaging applicationSend SMS & email messagesIntercept incoming SMS messages
WindowsMobile.Status Query 100+ system propertiesGet notified of changes
WindowsMobile.ConfigurationConfiguration Manager
WindowsMobile.TelephonyInitiate phone calls
WindowsMobile.FormsContact Picker DialogPicture Picker DialogCamera Capture Dialog
Integrating WithIntegrating WithOutlook MobileOutlook Mobile
It All Starts At OutlookSessionIt All Starts At OutlookSession
OutlookSession outlook = new OutlookSession();int contactCount = outlook.Contacts.Items.Count;
Folders And CollectionsFolders And Collections
One folder per typeOne folder per type
Each has a Each has a collectioncollection
Enumerate itemsEnumerate items
Check capabilitiesCheck capabilities
Sort & FilterSort & Filter
Add & RemoveAdd & Remove
ListChanged eventListChanged event
Appointments, Contacts, Appointments, Contacts, And TasksAnd Tasks
Lots of properties and eventsLots of properties and events
Don’t forget Don’t forget Update()Update()
OutlookSession outlook = new OutlookSession();Contact me = new Contact();me.FullName = “Gaurav”;outlook.Contacts.Items.Add( me ); // <-- Savedme.JobTitle = “DE”; me.Update(); // <-- Saved
Managed POOM: Managed POOM: Working with ContactsWorking with Contacts
Appointment And Task Can Appointment And Task Can Be RecurringBe RecurringRecurrence TypeRecurrence Type Properties to UseProperties to Use ExampleExampleDailyDaily IntervalInterval Every 4 daysEvery 4 days
WeeklyWeekly IntervalIntervalDaysOfWeekMaskDaysOfWeekMask
Every Monday and Every Monday and TuesdayTuesday
MonthlyMonthly IntervalIntervalDayOfMonthDayOfMonth Every 3 monthsEvery 3 months
MonthlyByNumberMonthlyByNumberIntervalIntervalDaysOfWeekMaskDaysOfWeekMaskInstanceInstance
Second Friday of Second Friday of each montheach month
YearlyYearly DayOfMonthDayOfMonthMonthOfYearMonthOfYear May 10May 10thth of each year of each year
YearlyByNumberYearlyByNumberDaysOfWeekMaskDaysOfWeekMaskInstanceInstanceMonthOfYearMonthOfYear
Second Tuesday in Second Tuesday in May of each yearMay of each year
(All)(All)PatternStartDatePatternStartDatePatternEndDatePatternEndDateNoEndDateNoEndDate
Items Can Be Shown In Items Can Be Shown In Outlook Mobile With ShowDialogOutlook Mobile With ShowDialogAppointment appt = new Appointment();appt.Subject = "Launch Windows Mobile 5.0!";appt.AllDayEvent = true;appt.Start = new DateTime(2005, 5, 10);outlook.Appointments.Items.Add(appt);appt.ShowDialog();
Add Your Own Properties Add Your Own Properties To PIM ItemsTo PIM Items
Contact myCustomer;// ...if(!myCustomer.Properties.Contains(“Employee ID”)){ myCustomer.Properties.Add("Employee ID", typeof(string));}myCustomer.Properties["Employee ID"] = "ABC1234";
1.1. See if the property has been definedSee if the property has been defined
2.2. If not, define itIf not, define it
3.3. Use itUse it
Working With Item IDsWorking With Item IDs
string idString;
// … Read idString from a file, registry, or database
int idNumber = Int32.Parse( idString );ItemID id = new ItemID( idNumber );Contact c = new Contact( id );
Store references to items by their IDStore references to items by their ID
Retrieve items by their IDRetrieve items by their ID
Contact c;// …string idString = c.ItemID.ToString();
Sending E-Mail And SMSSending E-Mail And SMS
SmsMessage msg = new SmsMessage();
msg.To.Add( new Recipient(“555-1212"));
msg.Body = “Hello World!";
msg.Send();
Contacts Are Not RecipientsContacts Are Not RecipientsContact myCustomer;// ...EmailMessage msg = new EmailMessage();msg.To.Add( myCustomer ); // Won’t compile!msg.To.Add( new Recipient( myCustomer.Email2Address ) ); // OK
Managed POOM: Managed POOM: Working with MessagingWorking with Messaging
Control The Messaging Control The Messaging ApplicationApplication
Display the compose formDisplay the compose form
Display the inboxDisplay the inbox
Initiate synchronizationInitiate synchronization
Create rich mobile apps byCreate rich mobile apps byintercepting SMS messagesintercepting SMS messages
Intercept SMS Messages In Intercept SMS Messages In Managed CodeManaged Code
MessageInterceptor sms;
void Form_Load( ... ){ sms = new MessageInterceptor(); //... Set optional properties here sms.MessageReceived += new EventHandler(sms_MessageReceived);}
void sms_MessageReceived(...){ //... Handle incoming message}
Specify What Happens to Specify What Happens to Intercepted MessagesIntercepted Messages
MessageInterceptor sms;
void Form_Load( ... ){ sms = new MessageInterceptor(); sms.InterceptionAction = InterceptionAction.NotifyAndDelete; sms.MessageReceived += new EventHandler(sms_MessageReceived);}
void sms_MessageReceived(...){ //... Handle incoming message}
Intercept SMS Messages In Intercept SMS Messages In Native CodeNative Code//=================================================================// MonitorThread - Monitors event for timer notification //DWORD WINAPI MonitorThread (PVOID pArg) { TEXT_PROVIDER_SPECIFIC_DATA tpsd; SMS_HANDLE smshHandle = (SMS_HANDLE)pArg; PMYMSG_STRUCT pNextMsg; BYTE bBuffer[MAXMESSAGELEN]; PBYTE pIn; SYSTEMTIME st; HANDLE hWait[2]; HRESULT hr; int rc; DWORD dwInSize, dwSize, dwRead = 0;
hWait[0] = g_hReadEvent; // Need two events since it isn't hWait[1] = g_hQuitEvent; // allowed for us to signal SMS event.
while (g_fContinue) { rc = WaitForMultipleObjects (2, hWait, FALSE, INFINITE); if (!g_fContinue || (rc != WAIT_OBJECT_0)) break; // Point to the next free entry in the array pNextMsg = &g_pMsgDB->pMsgs[g_pMsgDB->nMsgCnt];
// Get the message size hr = SmsGetMessageSize (smshHandle, &dwSize); if (hr != ERROR_SUCCESS) continue;
// Check for message larger than std buffer if (dwSize > sizeof (pNextMsg->wcMessage)) { if (dwSize > MAXMESSAGELEN) continue; pIn = bBuffer; dwInSize = MAXMESSAGELEN; } else { pIn = (PBYTE)pNextMsg->wcMessage; dwInSize = sizeof (pNextMsg->wcMessage); } // Set up provider specific data tpsd.dwMessageOptions = PS_MESSAGE_OPTION_NONE; tpsd.psMessageClass = PS_MESSAGE_CLASS0; tpsd.psReplaceOption = PSRO_NONE; tpsd.dwHeaderDataSize = 0;
// Read the message hr = SmsReadMessage (smshHandle, NULL, &pNextMsg-
>smsAddr, &st, (PBYTE)pIn, dwInSize, (PBYTE)&tpsd, sizeof(TEXT_PROVIDER_SPECIFIC_DATA), &dwRead); if (hr == ERROR_SUCCESS) { // Convert GMT message time to local time FILETIME ft, ftLocal; SystemTimeToFileTime (&st, &ft); FileTimeToLocalFileTime (&ft, &ftLocal); FileTimeToSystemTime (&ftLocal, &pNextMsg->stMsg);
// If using alt buffer, copy to std buff if ((DWORD)pIn == (DWORD)pNextMsg->wcMessage) { pNextMsg->nSize = (int) dwRead; } else { memset (pNextMsg->wcMessage, 0, sizeof(pNextMsg->wcMessage)); memcpy (pNextMsg->wcMessage, pIn, sizeof(pNextMsg->wcMessage)-2); pNextMsg->nSize = sizeof(pNextMsg->wcMessage); } // Increment message count if (g_pMsgDB->nMsgCnt < MAX_MSGS-1) { if (g_hMain) PostMessage (g_hMain, MYMSG_TELLNOTIFY, 1, g_pMsgDB->nMsgCnt); g_pMsgDB->nMsgCnt++; } } else { ErrorBox (g_hMain, TEXT("Error %x (%d) reading msg"), hr, GetLastError()); break; } } SmsClose (smshHandle); return 0;}
Making use of SMS Making use of SMS interceptioninterception
Create smart mobile apps with Create smart mobile apps with the State & Notification Brokerthe State & Notification Broker
Why Is This So Hard?Why Is This So Hard?
ProblemsProblemsDifferent APIs for querying different Different APIs for querying different propertiesproperties
Different change notification mechanisms Different change notification mechanisms for different propertiesfor different properties
Many properties not exposed Many properties not exposed (especially in .NET CF)(especially in .NET CF)
No standard way for OEMs and ISVs to No standard way for OEMs and ISVs to expose their own propertiesexpose their own properties
State And Notification State And Notification Broker StrategyBroker Strategy
1.1. Placement of useful information in Placement of useful information in documented registry locationsdocumented registry locations
2.2. Native APIs to get notified of changes Native APIs to get notified of changes to any registry valueto any registry value
3.3. Managed wrapper around native APIsManaged wrapper around native APIs
State And Notification State And Notification Broker DesignBroker Design
RegistryRegistry
Interesting ValuesInteresting Values
SNAPI.hSNAPI.hRegExt.hRegExt.h
Microsoft.WindowsMobile.StatusMicrosoft.WindowsMobile.Status
There Are There Are Over 100 Over 100 System System PropertiesProperties
Power & BatteryPower & BatteryAppointmentsAppointmentsMedia Player Media Player ConnectivityConnectivityActiveSyncActiveSyncMessagingMessagingTelephonyTelephonyHardwareHardwareTasksTasksShellShell
Get Change NotificationsGet Change Notifications
1.1. Create a SystemState objectCreate a SystemState object
2.2. Attach an event handlerAttach an event handler
SystemState callerId = new SystemState( SystemProperty.PhoneIncomingCallerContact);
callerId.Changed += new EventHandler(callerId_Changed);
void callerId_Changed(object sender, ChangeEventArgs e){ Contact caller = (Contact)callerId.CurrentValue; // ...}
Two Ways To Query For Two Ways To Query For Current ValuesCurrent Values
1.1. StaticStaticStrongly typed, quick and easyStrongly typed, quick and easy
2.2. DynamicDynamic
Contact c = Contact c = SystemState.PhoneIncomingCallerContact;SystemState.PhoneIncomingCallerContact;
SystemState callerId = new SystemState(SystemState callerId = new SystemState( SystemProperty.PhoneIncomingCallerContact);SystemProperty.PhoneIncomingCallerContact);
Contact c = (Contact)callerId.CurrentValue;Contact c = (Contact)callerId.CurrentValue;
The State And Notification The State And Notification Broker Is ExtensibleBroker Is Extensible
Publish your own statePublish your own state
Get notified of changes to Get notified of changes to anyany registry registry valuevalue
Get Notified While Your Get Notified While Your Application Is Not RunningApplication Is Not Running
Can be used forCan be used forSMS InterceptionSMS Interception
State and Notification BrokerState and Notification Broker
When a change occursWhen a change occurs1.1. Windows Mobile launches the applicationWindows Mobile launches the application
2.2. Application hooks up an event handerApplication hooks up an event hander
3.3. Event is firedEvent is fired
SystemState missedCall;
void Form_Load( … ){ if(!SystemState.IsApplicationLauncherEnabled(“MyApp.MissedCall”)) { missedCall = new SystemState( SystemProperty.PhoneMissedCall ); missedCall.EnableApplicationLauncher( “MyApp.MissedCall” ); } else { SystemState missedCall = new SystemState(“MyApp.MissedCall”); } missedCall.Changed += new EventHandler( missedCall_Changed );}
App Launching With The App Launching With The State & Notification BrokerState & Notification Broker
MessageInterceptor sms;
void Form_Load( … ){ if(!MessageInterceptor.IsApplicationLauncherEnabled(“MyApp.SMS”)) { sms = new MessageInterceptor(); sms.EnableApplicationLauncher( “MyApp.SMS” ); } else { MessageInterceptor sms = new SystemState(“MyApp.SMS”); } sms.MessageReceived += new EventHandler( sms_MessageReceived );}
App Launching With The App Launching With The SMS InterceptionSMS Interception
Conditions Prevent Conditions Prevent Unnecessary NotificationsUnnecessary Notifications
Very important for app-launching Very important for app-launching notifications!notifications!
Comparison Types:Comparison Types:
StringString Equal, NotEqual, Equal, NotEqual, StartsWith, EndsWith, ContainsStartsWith, EndsWith, Contains
IntegerInteger Equal, NotEqual, Equal, NotEqual, Greater, GreaterOrEqual,Greater, GreaterOrEqual,Less, LessOrEqualLess, LessOrEqual
BinaryBinary Not supportedNot supported
Setting Conditions With The Setting Conditions With The State & Notification BrokerState & Notification Broker
SystemState missedCall;
void Form_Load( … ){ // … missedCall = new SystemState( SystemProperty.PhoneMissedCall );
missedCall.ComparisonType = StatusComparisonType.Equal; missedCall.ComparisonValue = true;
missedCall.Changed += new EventHandler( missedCall_Changed );}
Other ResourcesOther ResourcesWindows Mobile 5.0 SDKWindows Mobile 5.0 SDK
http://http://msdn.microsoft.commsdn.microsoft.com/mobility//mobility/
Windows Mobile Team BlogWindows Mobile Team Bloghttp://http://blogs.msdn.com/windowsmobileblogs.msdn.com/windowsmobile
Migration FAQ for DevelopersMigration FAQ for Developershttp://msdn.microsoft.com/library/en-us/dnppcgehttp://msdn.microsoft.com/library/en-us/dnppcgen/html/migration_developers_faq.aspn/html/migration_developers_faq.asp
WinToolZoneWinToolZonehttp://www.wintoolzone.com/http://www.wintoolzone.com/
.NET Insights.NET Insightshttp://http://geekswithblogs.netgeekswithblogs.net/khanna//khanna/
Tools & ResourcesTools & Resources
msdn.microsoft.com/msdn.microsoft.com/ embeddedembedded
microsoft.public.microsoft.public. windowsxp.embeddedwindowsxp.embedded windowsce.platbuilderwindowsce.platbuilder windowsce.embedded.vcwindowsce.embedded.vc
blogs.msdn.com/blogs.msdn.com/ mikehallmikehall
Windows CE 5.0 Eval KitWindows CE 5.0 Eval KitWindows XP Embedded Eval KitWindows XP Embedded Eval Kit
msdn.microsoft.com/msdn.microsoft.com/ mobilitymobility
microsoft.public.microsoft.public. pocketpc.developer pocketpc.developer smartphone.developer smartphone.developer dotnet.framework.compactframeworkdotnet.framework.compactframework
blogs.msdn.com/blogs.msdn.com/ windowsmobilewindowsmobile vsdteamvsdteam netcfteamnetcfteam
Windows Mobile 5.0 Eval KitWindows Mobile 5.0 Eval Kit
WebsitesWebsites
NewsgroupsNewsgroups
BlogsBlogs
ToolsTools
BuildBuild DevelopDevelop
© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Your FeedbackYour Feedbackis Important!is Important!
Please Fill Out the Please Fill Out the feedback formfeedback form
© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.