在WindowsPhone中需要調用系統資源的話需要用到啟動器(Launcher)和選擇器(Choosers)。
其實已經很多人寫過了,最近正好用到,再總結下吧…
先寫啟動器(Launcher),等下周有時間再寫選擇器(Choosers)。
1,Launchers
目前WindowsPhone啟動器一共有15個
其中7.0支持的有10個:
7.1新增了5個:
2,BingMapsDirectionsTask
BingMapsDirectionsTask的功能是一個基於bing地圖的路徑導航,屬性有兩個(起點和終點),值類型為LabeledMapLocation
Name | Description | |
---|---|---|
![]() |
End | The ending location for which driving directions are displayed. |
![]() |
Start | The starting location for which driving directions are displayed. |
用法也很簡單:
BingMapsDirectionsTask bingMapsDirectionsTask = new BingMapsDirectionsTask();
GeoCoordinate spaceNeedleLocation = new GeoCoordinate(0,0);
LabeledMapLocation spaceNeedleLML1 = new LabeledMapLocation("Somewhere", spaceNeedleLocation);
LabeledMapLocation spaceNeedleLML2 = new LabeledMapLocation("qingdao", null);
bingMapsDirectionsTask.End = spaceNeedleLML2;
bingMapsDirectionsTask.Start = spaceNeedleLML1;
bingMapsDirectionsTask.Show();
其中LabeledMapLocation的第二個參數為地理坐標,如果為NULL的話,bing地圖會根據第一個參數的字符串進行搜索
另外如果不設置bingMapsDirectionsTask.Start的話,默認以當前GPS定位為出發地址。
效果:
最后,bing map在米國貌似不錯,天朝比較坑爹…路徑導航基本沒戲….
還有手機區域語言選中國,基本不工作,選英國、米國都正常…
3,BingMapsTask
BingMapsTask的功能就是一個比較簡單的bing地圖調用,你可以設置地圖的中間點、縮放級別或者領用bing地圖搜索。
Name | Description | |
---|---|---|
![]() |
Center | Gets or sets the location that will be used as the center point for the map. |
![]() |
SearchTerm | Gets or sets the search term that is used to find and tag locations on the map. |
![]() |
ZoomLevel | Gets or sets the initial zoom level of the map. |
BingMapsTask bingMapsTask = new BingMapsTask();
bingMapsTask.Center = new GeoCoordinate(47.6204,-122.3493);
//bingMapsTask.SearchTerm = "qingdao";
bingMapsTask.ZoomLevel = 50;
bingMapsTask.Show();
其中ZoomLevel是double型,而且必須大於0
效果:
4,ConnectionSettingsTask
ConnectionSettingsTask功能是快速導航到WP的網絡設置(包括WIFI、數據連接、藍牙和飛行模式)
Name | Description | |
---|---|---|
![]() |
ConnectionSettingsType | Gets or sets the type of network connection settings that will be displayed. |
ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.WiFi;
//connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.AirplaneMode;
//connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.Bluetooth;
//connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.Cellular;
connectionSettingsTask.Show();
效果就不加了,相當於快捷方式而已
5,EmailComposeTask
EmailComposeTask功能是調用綁定的郵箱發送郵件。
Name | Description | |
---|---|---|
![]() |
Bcc | Gets or sets the recipients on the Bcc line of the new email message. |
![]() |
Body | Gets or sets the body of the new email message. |
![]() |
Cc | Gets or sets the recipients on the Cc line of the new email message. |
![]() |
CodePage | Gets or sets the character set that will be used to display the message content. |
![]() |
Subject | Gets or sets the subject of the new email message. |
![]() |
To | Gets or sets the recipients on the To line of the new email message. |
EmailComposeTask emailComposeTask = new EmailComposeTask();
emailComposeTask.Subject = "message subject";
emailComposeTask.Body = "message body";
emailComposeTask.To = "recipient@example.com";
emailComposeTask.Cc = "cc@example.com";
emailComposeTask.Bcc = "bcc@example.com";
emailComposeTask.Show();
標題、正文、收件人、抄送、密送,不多說了..
效果:
6,MarketplaceDetailTask
MarketplaceDetailTask功能是導航到市場上的軟件(軟件推薦或者提示用戶下載其他賬戶發布的新版本或相關應用的時候很有用)
Name | Description | |
---|---|---|
![]() |
ContentIdentifier | Gets or sets the unique identifier for the product to be displayed. |
![]() |
ContentType | Gets or sets the type of content displayed in the Windows Phone Marketplace client application. |
MarketplaceDetailTask marketplaceDetailTask = new MarketplaceDetailTask();
marketplaceDetailTask.ContentIdentifier = "c14e93aa-27d7-df11-a844-00237de2db9e";
//marketplaceDetailTask.ContentType = MarketplaceContentType.Applications;
marketplaceDetailTask.Show();
ContentType默認為MarketplaceContentType.Applications,不用設置就可以
效果:
7,MarketplaceHubTask
MarketplaceHubTask功能很簡單,就是導航到Marketplace,可以選擇Application或者Music。
Name | Description | |
---|---|---|
![]() |
ContentType | Gets or sets the type of content displayed in the Windows Phone Marketplace client application. |
MarketplaceHubTask marketplaceHubTask = new MarketplaceHubTask();
marketplaceHubTask.ContentType = MarketplaceContentType.Music;
//marketplaceHubTask.ContentType = MarketplaceContentType.Applications;
marketplaceHubTask.Show();
效果:
8,MarketplaceReviewTask
MarketplaceReviewTask功能是導航到該應用的應用評分界面(一般應用的about里估計會用到)
MarketplaceReviewTask marketplaceReviewTask = new MarketplaceReviewTask();
marketplaceReviewTask.Show();
效果:
9,MarketplaceSearchTask
MarketplaceSearchTask功能是市場搜索
Name | Description | |
---|---|---|
![]() |
ContentType | Gets or sets the type of content displayed in the Windows Phone Marketplace client application. |
![]() |
SearchTerms | Gets or sets the search terms. |
MarketplaceSearchTask marketplaceSearchTask = new MarketplaceSearchTask();
//marketplaceSearchTask.ContentType = MarketplaceContentType.Applications;
marketplaceSearchTask.ContentType = MarketplaceContentType.Music;
marketplaceSearchTask.SearchTerms = "be what you wanna be";
marketplaceSearchTask.Show();
ContentType依舊默認為Applications,另外搜索中文亂碼…
效果:
10,MediaPlayerLauncher
MediaPlayerLauncher可以調用手機播放器來播放音樂、視頻。
Name | Description | |
---|---|---|
![]() |
Controls | Gets or sets the flags that determine which controls are displayed in the media player application. |
![]() |
Location | Sets the location of the media file to be played. The MediaLocationType enumeration is used to specify either isolated storage or the application’s installation folder. |
![]() |
Media | Gets or sets the media played with the media player application. |
![]() |
Orientation | Gets or sets the orientation in which the media player will be displayed when launched. |
MediaPlayerLauncher mediaPlayerLauncher = new MediaPlayerLauncher();
//mediaPlayerLauncher.Media = new Uri("Trouble Is A Friend.mp3", UriKind.Relative);
mediaPlayerLauncher.Media = new Uri("Wildlife.wmv", UriKind.Relative);
mediaPlayerLauncher.Location = MediaLocationType.Install;
mediaPlayerLauncher.Controls = MediaPlaybackControls.Pause | MediaPlaybackControls.Stop;
mediaPlayerLauncher.Orientation = MediaPlayerOrientation.Portrait;
mediaPlayerLauncher.Show();
Location需要選擇是在隔離存儲空間(MediaLocationType.Data)還是安裝目錄(MediaLocationType.Install)
效果:
11,PhoneCallTask
PhoneCallTask功能就是撥打電話
Name | Description | |
---|---|---|
![]() |
DisplayName | Gets or sets the name that is displayed when the Phone application is launched. |
![]() |
PhoneNumber | Gets or sets the phone number that is dialed when the Phone application is launched. |
PhoneCallTask phoneCallTask = new PhoneCallTask();
phoneCallTask.PhoneNumber = "2065550123";
phoneCallTask.DisplayName = "Gage";
phoneCallTask.Show();
效果:
12,SearchTask
SearchTask功能是調用搜索(貌似依舊是bing…)
Name | Description | |
---|---|---|
![]() |
SearchQuery | Gets or sets the search query that the Web Search application will use when it is launched. |
SearchTask searchTask = new SearchTask();
searchTask.SearchQuery = "外匯";
searchTask.Show();
顯示結果為網絡、本地和圖片,終於支持中文了
效果:
13,ShareLinkTask
ShareLinkTask可以調用你綁定的賬戶(Live、Facebook、Twitter)分享消息
Name | Description | |
---|---|---|
![]() |
LinkUri | Gets or sets the link URI that will be displayed in the link sharing dialog. |
![]() |
Message | Gets or sets the message that will accompany the link when it is shared. |
![]() |
Title | Gets or sets the title of the link to be shared. |
ShareLinkTask shareLinkTask = new ShareLinkTask();
shareLinkTask.Title = "Code Samples";
shareLinkTask.LinkUri = new Uri("http://msdn.microsoft.com/en-us/library/ff431744(v=VS.92).aspx", UriKind.Absolute);
shareLinkTask.Message = "Here are some great code samples for Windows Phone.";
shareLinkTask.Show();
不用多說,看名字就知道各個屬性咋用了,要是啥時候微博、QQ能加入就NB了…
效果:
14,ShareStatusTask
ShareStatusTask功能是分享狀態,其實和上面ShareLinkTask類似。
Name | Description | |
---|---|---|
![]() |
Status | Gets or sets the status message to be shared. |
ShareStatusTask shareStatusTask = new ShareStatusTask();
shareStatusTask.Status = "I'm developing a Windows Phone application!";
shareStatusTask.Show();
還是和上面一樣,能加微博就無敵了…
效果:
15,SmsComposeTask
SmsComposeTask功能就是發送短信。
Name | Description | |
---|---|---|
![]() |
Body | Gets or sets the body text of the new SMS message. |
![]() |
To | Gets or sets the recipient list for the new SMS message. |
SmsComposeTask smsComposeTask = new SmsComposeTask();
smsComposeTask.To = "2065550123";
smsComposeTask.Body = "Try this new application. It's great!";
smsComposeTask.Show();
不多說了..
效果:
16,WebBrowserTask
WebBrowserTask功能就是調用瀏覽器。
Name | Description | |
---|---|---|
![]() |
Uri | Gets or sets the URI to which the web browser application will navigate when it is launched. |
![]() |
URL | Obsolete. Gets or sets the URL to which the web browser application will navigate when it is launched. |
WebBrowserTask webBrowserTask = new WebBrowserTask();
//webBrowserTask.URL = "http://msdn.microsoft.com";
webBrowserTask.Uri = new Uri("http://msdn.microsoft.com", UriKind.Absolute);
webBrowserTask.Show();
url雖然提示過時,不過也能用,不過推薦用Uri。
效果:
15個啟動器介紹完畢,下周有時間再寫下選擇器。
參考: http://msdn.microsoft.com/en-us/library/ff769550(v=vs.92).aspx
實例源碼: