Document directory
- 2. Lock the screen background
- 2. Lock screen notification
- 3. Start the application from the lock Screen Settings page
- 1. Read-Only contact Access
- 2. Custom contact Storage
This section provides integrated support for Windows phone 8 systems, including selector, screen lock, and contact access. The selector lists the support provided by several built-in applications. The lock screen shows that we can provide background images, screen notifications, and other functions for the lock screen; contact access demonstrates the Management and Maintenance of contacts and read-only access.
Quick Navigation:
I. Selector
2. Lock the screen
3. Contact access
I. Selector
The selector provides support for mobile phone built-in apps for your development. With the selector, you can directly call the camera app to capture a photo to your app, or call the contact's related information, save ringtones.
Most commonly used selectors are listed below:
1. Address Selector
2. Camera Photo Selector
3. Email Selector
4. Telephone Selector
5. Photo Selector
6. Save the contact Selector
7. Save the email address Selector
8. Save the phone number Selector
9. Save the ringtone Selector
The following code lists the call methods.
[C #]
// Address selector void showAddressChooserTask () {var addressChooserTask = new AddressChooserTask (); addressChooserTask. completed + = new EventHandler <AddressResult> (a, B) => {if (B. taskResult = TaskResult. OK) {MessageBox. show (B. displayName + ":" + B. address) ;}}); addressChooserTask. show () ;}// Camera Photo selector void showCameraCaptureTask () {var cameraCaptureTask = new CameraCaptureTask (); cameraCaptureTask. Completed + = new EventHandler <PhotoResult> (a, B) => {if (B. taskResult = TaskResult. OK) {Image image = new Image (); var bitmapImage = new BitmapImage (); bitmapImage. setSource (B. chosenPhoto); image. source = bitmapImage; ContentPanel. children. add (image); MessageBox. show (B. originalFileName) ;}}); cameraCaptureTask. show () ;}// email selector void showEmailAddressChooserTask () {var emailAddressChooserTask = New EmailAddressChooserTask (); emailAddressChooserTask. completed + = new EventHandler <EmailResult> (a, B) => {if (B. taskResult = TaskResult. OK) {MessageBox. show (B. displayName + ":" + B. email) ;}}); emailAddressChooserTask. show () ;}// call selector void showPhoneNumberChooserTask () {var phoneNumberChooserTask = new PhoneNumberChooserTask (); phoneNumberChooserTask. completed + = new EventHandler <Pho NeNumberResult> (a, B) => {if (B. taskResult = TaskResult. OK) {MessageBox. show (B. displayName + ":" + B. phoneNumber) ;}}); phoneNumberChooserTask. show () ;}// photo selector void showPhotoChooserTask () {var photoChooserTask = new PhotoChooserTask (); photoChooserTask. completed + = new EventHandler <PhotoResult> (a, B) => {if (B. taskResult = TaskResult. OK) {Image image = new Image (); var bitmapImage = New BitmapImage (); bitmapImage. setSource (B. chosenPhoto); image. source = bitmapImage; ContentPanel. children. add (image); MessageBox. show (B. originalFileName) ;}}); photoChooserTask. show () ;}// Save the contact selector void showSaveContactTask () {var saveContactTask = new SaveContactTask (); saveContactTask. completed + = new EventHandler <SaveContactResult> (a, B) => {switch (B. taskResult) {case TaskResult. OK: Mess AgeBox. Show ("saved successfully. "); Break; case TaskResult. Cancel: MessageBox. Show (" Cancel saving. "); Break; case TaskResult. None: MessageBox. Show (" failed to save. "); Break ;}}); // Add some default values saveContactTask. firstName = "3"; saveContactTask. lastName = "Zhang"; saveContactTask. mobilePhone = "13900000000"; saveContactTask. show () ;}// Save the email address selector void showSaveEmailAddressTask () {var saveEmailAddressTask = new SaveEmailAddressTask (); saveEmailAddressTask. completed + = new EventHandler <TaskEventArgs> (a, B) => {switch (B. taskResult) {case TaskResult. OK: MessageBox. sh Ow ("saved successfully. "); Break; case TaskResult. Cancel: MessageBox. Show (" Cancel saving. "); Break; case TaskResult. None: MessageBox. Show (" failed to save. "); Break ;}}); // Add the default value saveEmailAddressTask. email = "mail@163.com"; saveEmailAddressTask. show () ;}// Save the phone number selector void showSavePhoneNumberTask () {var savePhoneNumberTask = new SavePhoneNumberTask (); savePhoneNumberTask. completed + = new EventHandler <TaskEventArgs> (a, B) => {switch (B. taskResult) {case TaskResult. OK: MessageBox. show ("saved successfully. "); Break; case TaskResult. Cancel: MessageBox. Show (" Cancel saving. "); Break; case TaskResult. None: MessageBox. Show (" failed to save. "); Break ;}}); // Add the default value savePhoneNumberTask. phoneNumber = "13900000000"; savePhoneNumberTask. show () ;}// Save the ringtone selector void showSaveRingtoneTask () {var saveRingtoneTask = new SaveRingtoneTask (); saveRingtoneTask. completed + = new EventHandler <TaskEventArgs> (a, B) => {switch (B. taskResult) {case TaskResult. OK: MessageBox. show ("saved successfully. "); Break; case TaskResult. Cancel: MessageBox. Show (" Cancel saving. "); Break; case TaskResult. None: MessageBox. Show (" failed to save. "); Break ;}}); // the path of the ringtone file to saveRingtoneTask. source = new Uri ("appdata:/smoke easy to cool"); // The name saveRingtoneTask of the ringtone displayed in the list. displayName = "fireworks are cold"; saveRingtoneTask. show ();}
2. Lock the screen
On the screen lock page, our app can update background images and add screen notifications.
2. Lock the screen background
To enable the application to update the locked screen background image, we must declare it in the Application List file. Right-click the open method, select the XML text editor to open WMAppManifest. xml, and add the extended content under Tokens.
[XML]
<Extensions> <! -- Indicates that the current application can provide background images for the locked screen --> <Extension ExtensionName = "LockScreen_Background" ConsumerID = "{identifier}" TaskID = "_ default"/> </Extensions>
The following figure shows the 1.jpg image under the installation file.
[C #]
Private async void SetLockImg () {try {// indicates whether the current application is locking the screen provider var isProvider = Windows. Phone. System. UserProfile. LockScreenManager. IsProvidedByCurrentApplication; if (! IsProvider) {// set the current application to lock the screen provider var op = await Windows. phone. system. userProfile. lockScreenManager. requestAccessAsync (); // whether the application has been set to lock the screen provider isProvider = op = Windows. phone. system. userProfile. lockScreenRequestResult. granted;} if (isProvider) {// sets the background image for locking the screen for Windows. phone. system. userProfile. lockScreen. setImageUri (new Uri ("ms-appx: // 1.jpg", UriKind. absolute); // obtain the locked screen image var currentImage = Windows. phone. system. userProfile. lockScreen. getImageUri (); System. diagnostics. debug. writeLine ("The new lock screen background image is set to {0}", currentImage. toString ();} else {MessageBox. show ("screen background cannot be locked") ;}} catch {}}
2. Lock screen notification
The application can set the notification information and display it to the notification area on the locked screen. First, we need to specify the png image file used to display the logo in the Application List file. On the right-click the option, select the xmlcommunity editor to open wmappmanifest.xml, and set the logo as lockimage.png. Modify the DeviceLockImageURI element of the Tokens tag as follows:
[XML]
<DeviceLockImageURI IsRelative="true" IsResource="false">LockImage.png</DeviceLockImageURI>
In addition, we also need to declare in the inventory file that we can display the notification in the lock screen. Right-click the open method, select the XML text editor to open WMAppManifest. xml, and add the extended content under Tokens.
[XML]
<Extensions> <! -- Indicates that the current application can add screen notifications --> <Extension ExtensionName = "lockscreen_icationication_iconcount" ConsumerID = "{consumer}" TaskID = "_ default"/> <Extension ExtensionName = "lockscreen_icationication_textfield "= "{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID = "_ default"/> </Extensions>
After the settings are complete, we can lock the screen display notification, but the specific display also requires the user to lock the screen page set in the system, add our application to lock the screen notification provider. After all settings are complete, as long as the default icon has a notification value, the screen will be displayed when the screen is locked.
3. Start the application from the lock Screen Settings page
After registering as the lock screen background provider, our application can start from the lock Screen Settings page. By default, the mainpage is opened, and we need to process the start uri.
[C #]
// Processing when the screen setting page is opened from the System lock protected override void OnNavigatedTo (System. windows. navigation. navigationEventArgs e) {base. onNavigatedTo (e); string lockscreenKey = "WallpaperSettings"; string lockscreenValue = "0"; bool lockscreenValueExists = NavigationContext. queryString. tryGetValue (lockscreenKey, out lockscreenValue); if (lockscreenValueExists) {// you can define a page to lock the screen background enhancement settings. MessageBox. Show ("opens from the locked Screen Settings. ");}}
3. Contact access
The mobile phone's built-in Contact Database supports programming for access. There are two access methods: read-only access and addition, deletion, modification, and query.
1. Read-Only contact Access
The following shows the list of read-only contacts returned through query.
[C #]
// Contact data private void Button_Click_1 (object sender, RoutedEventArgs e) {Contacts cons = new Contacts (); cons. searchCompleted + = new EventHandler <ContactsSearchEventArgs> (Contacts_SearchCompleted); // parameter 1: keyword; parameter 2: filter type, including the display name, phone number, email address, fixed to the Start Screen, etc. cons. searchAsync ("139", FilterKind. phoneNumber, "status");} void Contacts_SearchCompleted (object sender, ContactsSearchEventArgs e) {// listbox1.ItemsSource = e. results ;}
2. Custom contact Storage
In this way, you can add, delete, modify, and query the contact list of the system. We will demonstrate how to perform this operation.
[XAML]
<Grid x: Name = "ContentPanel" Grid. row = "1" Margin = "10,173,"> <ListBox x: Name = "listbox1" Margin = ","> <ListBox. itemTemplate> <DataTemplate> <StackPanel Orientation = "Horizontal"> <TextBlock Text = "{Binding Id}"> </TextBlock> <TextBlock Text = ""> </TextBlock> <textBlock Text = "{Binding FamilyName}"> </TextBlock> <TextBlock Text = "{Binding GivenName}"> </TextBlock> </StackPanel> </DataTemplate> </ListBox. itemTemplate> </ListBox> <Button Content = "added" HorizontalAlignment = "Left" Margin = "10,603, 106,603,251 "verticalignment =" Top "Click =" Button_Click_1 "/> <Button Content =" modify "Margin =, 21 "Click =" Button_Click_2 "/> <Button Content =" delete "HorizontalAlignment =" Left "Margin =" 205,603, 24,556 "VerticalAlignment =" Top "Click =" Button_Click_3 "/> <TextBlock x: Name =" textblock1 "HorizontalAlignment =" Left "Margin =, 0, 0 "TextWrapping =" Wrap "Text =" "VerticalAlignment =" Top "/> <Button Content =" view mobile phone number "HorizontalAlignment =" Left "Margin =" 291,603, 224,533 "VerticalAlignment =" Top "Click =" Button_Click_4 "/> <Button Content =" read-only contact Access> "HorizontalAlignment =" Left "Margin =, 232 "VerticalAlignment =" Top "Width =" "Click =" Button_Click_5 "/> </Grid>
[C #]
Public partial class MainPage: PhoneApplicationPage {// constructor public MainPage () {InitializeComponent (); Query () ;}// Add a contact async Task Add (string familyName, string givenName) {ContactStore store = await ContactStore. createOrOpenAsync (); StoredContact contact = new StoredContact (store); contact. familyName = familyName; contact. givenName = givenName; // obtain the known contact attribute IDictionary <string, object> props = Await contact. getPropertiesAsync (); props. add (KnownContactProperties. telephone, "18600000000"); // get extended contact attributes IDictionary <string, object> extprops = await contact. getExtendedPropertiesAsync (); extprops. add ("extension", "extension property"); await contact. saveAsync ();} // Query the contact and bind it to the List async void Query () {ContactStore store = await ContactStore. createOrOpenAsync (); ContactQueryResult result = store. createContactQuery (); IReadOnlyList <StoredContact> contacts = await result. getContactsAsync (); listbox1.ItemsSource = contacts;} // query the known attributes async void GetPropertie (StoredContact contact) {IDictionary <string, object> props = await contact. getPropertiesAsync (); if (props. keys. contains (KnownContactProperties. telephone) {MessageBox. show ("Mobile:" + props [KnownContactProperties. telephone]. toString () ;}}// update the contact async Tas K Update (string Id) {try {ContactStore store = await ContactStore. CreateOrOpenAsync (); var contact = await store. FindContactByIdAsync (Id); if (contact! = Null) {contact. familyName = "Zhao"; contact. givenName = "6"; await contact. saveAsync () ;}} catch (Exception e) {textblock1.Text = e. message ;}// Delete the contact async private Task Delete (string Id) {try {ContactStore = await ContactStore. createOrOpenAsync (); await store. deleteContactAsync (Id);} catch (Exception e) {textblock1.Text = e. message ;}// added private async void Button_Click_1 (object sender, RoutedEventArgs e) {string [] familyNames = new string [] {"Zhao", "Qian ", "Sun", "Li", "Week"}; string [] givenNames = new string [] {"Cloud", "", "feiyan", "White ", "Gong Jin"}; Random r = new Random (); await Add (familyNames [r. next (0, familyNames. length)], givenNames [r. next (0, givenNames. length)]); Query () ;}// modify private async void Button_Click_2 (object sender, RoutedEventArgs e) {var contact = listbox1.SelectedValue as StoredContact; if (contact = null) return; await Update (contact. id); Query () ;}// Delete private async void Button_Click_3 (object sender, RoutedEventArgs e) {var contact = listbox1.SelectedValue as StoredContact; if (contact = null) return; await Delete (contact. id); Query () ;}// view the mobile phone number private void Button_Click_4 (object sender, RoutedEventArgs e) {var contact = listbox1.SelectedValue as StoredContact; if (contact = null) return; getPropertie (contact);} private void Button_Click_5 (object sender, RoutedEventArgs e) {NavigationService. navigate (new Uri ("/Page1.xaml", UriKind. relative ));}}
By Lipan)
Source: [Lipan] (http://www.cnblogs.com/lipan)
Copyright: The copyright of this article is shared by the author and the blog. The detailed link of this article must be noted during reprinting; otherwise, the author will be held legally liable. Previous Article: Windows phone 8 learning notes positioning map navigation
Series directory
Next article: No