Windows phone 8 study notes (9) integration

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

This section arranged before and no mention of Windows phone 8 system integration support, including the selector, lock screen, contacts, access. Selector lists relevant support provides several built-in applications; the lock screen shows we can provide the background image for the lock screen, screen notifications; contact access presentation of the contact management and read-only access.

Fast navigation:
A, selector
Two, the lock screen
Three, the contact access

A, selector

Selector for supporting mobile phone built-in applications for your development, through the selector you can directly call a photo camera used to capture your application, relevant information or call contact, save the bell etc.

Listed below are the most common selector:
1 address selector
2 camera selector
3 mailbox selector
4 telephone selector
The 5 photo selector
6 save contact selector
7 save email address selector
8 save telephone number selector
9 saving ringtone selector

The following code lists the method call.

[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 + "The address is: "+ b.Address);}}); (addressChooserTask.Show);} // camera 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(); } //Mailbox selector void showEmailAddressChooserTask() { var emailAddressChooserTask = new EmailAddressChooserTask(); emailAddressChooserTask.Completed += new EventHandler<EmailResult>((a, b) => { if (b.TaskResult == TaskResult.OK) { MessageBox.Show(b.DisplayName + "The mailbox is: "+ b.Email);}}); (emailAddressChooserTask.Show);} // telephone selector void showPhoneNumberChooserTask() { var phoneNumberChooserTask = new PhoneNumberChooserTask(); phoneNumberChooserTask.Completed += new EventHandler<PhoneNumberResult>((a, b) => { if (b.TaskResult == TaskResult.OK) { MessageBox.Show(b.DisplayName + "The telephone is: "+ 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 contact selector void showSaveContactTask() { var saveContactTask = new SaveContactTask(); saveContactTask.Completed += new EventHandler<SaveContactResult>((a, b) => { switch (b.TaskResult) { case TaskResult.OK: MessageBox.Show("Successfully saved. "); break; case TaskResult.Cancel: MessageBox.Show("Canceling saving. "); break; case TaskResult.None: MessageBox.Show("Save failed. "); break; } }); //Add some default values saveContactTask.FirstName = "Three"; saveContactTask.LastName = "Zhang"; saveContactTask.MobilePhone = "13900000000"; saveContactTask.Show(); } //Save email address selector void showSaveEmailAddressTask() { var saveEmailAddressTask = new SaveEmailAddressTask(); saveEmailAddressTask.Completed += new EventHandler<TaskEventArgs>((a, b) => { switch (b.TaskResult) { case TaskResult.OK: MessageBox.Show("Successfully saved. "); break; case TaskResult.Cancel: MessageBox.Show("Canceling saving. "); break; case TaskResult.None: MessageBox.Show("Save failed. "); break; } }); //Add default values saveEmailAddressTask.Email = ""; saveEmailAddressTask.Show(); } //Save number selector void showSavePhoneNumberTask() { var savePhoneNumberTask = new SavePhoneNumberTask(); savePhoneNumberTask.Completed += new EventHandler<TaskEventArgs>((a, b) => { switch (b.TaskResult) { case TaskResult.OK: MessageBox.Show("Successfully saved. "); break; case TaskResult.Cancel: MessageBox.Show("Canceling saving. "); break; case TaskResult.None: MessageBox.Show("Save failed. "); break; } }); //Add default values savePhoneNumberTask.PhoneNumber = "13900000000"; savePhoneNumberTask.Show(); } //Save the bell selector void showSaveRingtoneTask() { var saveRingtoneTask = new SaveRingtoneTask(); saveRingtoneTask.Completed += new EventHandler<TaskEventArgs>((a, b) => { switch (b.TaskResult) { case TaskResult.OK: MessageBox.Show("Successfully saved. "); break; case TaskResult.Cancel: MessageBox.Show("Canceling saving. "); break; case TaskResult.None: MessageBox.Show("Save failed. "); break; } }); //The file path saveRingtoneTask.Source = new Uri("appdata:/Fireworks easy cold.mp3"); //The bell in the list display name saveRingtoneTask.DisplayName = "Fireworks easy cold"; saveRingtoneTask.Show(); }

Two, the lock screen

Lock screen interface on a mobile phone, we can use the background image and add screen notice.

2 lock screen background

To make the application can update lock screen background image, we must be declared in the application manifest file. Right click to open the way, select the XML text editor to open the WMAppManifest.xml, add the extension content in Tokens.

[XML]
<Extensions> <!- indicates the current application can provide the background image for the lock screen> <Extension ExtensionName="LockScreen_Background" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" /> </Extensions>

Have a look below how to update the mobile phone lock screen background for the installation folder under the 1.jpg.

[C#]
private async void SetLockImg() { try { //The application is to lock the screen provider var isProvider = Windows.Phone.System.UserProfile.LockScreenManager.IsProvidedByCurrentApplication; if (!isProvider) { //Set the current application as the lock screen provider var op = await Windows.Phone.System.UserProfile.LockScreenManager.RequestAccessAsync(); //Whether the application has been set to lock the screen provides program isProvider = op == Windows.Phone.System.UserProfile.LockScreenRequestResult.Granted; } if (isProvider) { // Set lock screen background image Windows.Phone.System.UserProfile.LockScreen.SetImageUri(new Uri("ms-appx:///1.jpg", UriKind.Absolute)); // Image lock screen 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("Not to lock the screen background "); } } catch { } }

2 lock screen notifications

The application can set the notification information and display to the notification area lock screen, we need to first specify used to display the logo PNG picture files in the application manifest file. We right click Select open, select the XML text editor to open the WMAppManifest.xml, set the logo for LockImage.png. DeviceLockImageURI elements to modify the Tokens labeled as follows:

[XML]
<DeviceLockImageURI IsRelative="true" IsResource="false">LockImage.png</DeviceLockImageURI>

In addition, we also need to manifest file that we can show the notification on the lock screen. Right click to open the way, select the XML text editor to open the WMAppManifest.xml, add the extension content in Tokens.

[XML]
<Extensions> <!- indicates the current application can add screen notice --> <Extension ExtensionName="LockScreen_Notification_IconCount" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" /> <Extension ExtensionName="LockScreen_Notification_TextField" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" /> </Extensions>

After setting, we can notice in the lock screen display, but the show also requires the user to the lock screen page system settings, add our application for the lock screen notifications provider. All set, as long as the default icon notification numerical, this time lock screen will show.

3 from the lock screen settings page starting application

Registered provider for the lock screen background, we can use the lock screen settings page from the start, to open the default mainpage, we need to start URI.

[C#]
//From the system lock screen processing settings when the page opens. 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) { //Here you can define a lock screen background enhanced settings page. MessageBox.Show("Open the settings from the lock screen. "); } }

Three, the contact access

Mobile phone built-in contact database programming mode to access. We have access in two ways, one is read-only access, there is a can perform CRUD operations.

Contact 1 read-only access

The following demonstrates the query returns a read-only list.

[C#]
//Private void Button_Click_1 contact data(object sender, RoutedEventArgs e) { Contacts cons = new Contacts(); cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(Contacts_SearchCompleted); //Parameters of the 1: keyword; parameter 2: filter type, Contains the display name, phone number, email address, is fixed to the start screen etc. cons.SearchAsync("139", FilterKind.PhoneNumber, "State"); } void Contacts_SearchCompleted(object sender, ContactsSearchEventArgs e) { //Gets the collection to contacts listbox1.ItemsSource = e.Results; }

2 custom contact storage

In this way we can on the contact list to do all kinds of CRUD operations, we will demonstrate how to operate.

[XAML]
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <ListBox x:Name="listbox1" Margin="0,10,10,173"> <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="Newly added" HorizontalAlignment="Left" Margin="10,603,0,0" VerticalAlignment="Top" Click="Button_Click_1"/> <Button Content="Modify" Margin="106,603,251,21" Click="Button_Click_2"/> <Button Content="Delete" HorizontalAlignment="Left" Margin="205,603,0,0" VerticalAlignment="Top" Click="Button_Click_3"/> <TextBlock x:Name="textblock1" HorizontalAlignment="Left" Margin="24,556,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top"/> <Button Content="The mobile phone number" HorizontalAlignment="Left" Margin="291,603,0,0" VerticalAlignment="Top" Click="Button_Click_4"/> <Button Content="Access read-only contacts〉" HorizontalAlignment="Left" Margin="224,533,0,0" VerticalAlignment="Top" Width="232" Click="Button_Click_5"/> </Grid>

[C#]
public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { InitializeComponent(); Query(); } //Add new contact async Task Add(string familyName, string givenName) { ContactStore store = await ContactStore.CreateOrOpenAsync(); StoredContact contact = new StoredContact(store); contact.FamilyName = familyName; contact.GivenName = givenName; //Get known contact attributes IDictionary<string, object> props = await contact.GetPropertiesAsync(); props.Add(KnownContactProperties.Telephone, "18600000000"); //Get contacts attribute extension IDictionary<string, object> extprops = await contact.GetExtendedPropertiesAsync(); extprops.Add("Extension", "The extended attributes"); await contact.SaveAsync(); } //Query contact, And bound 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 of known properties async void GetPropertie(StoredContact contact) { IDictionary<string, object> props = await contact.GetPropertiesAsync(); if (props.Keys.Contains(KnownContactProperties.Telephone)) { MessageBox.Show("Mobile phone: " + props[KnownContactProperties.Telephone].ToString()); } } //Update the contact async Task Update(string Id) { try { ContactStore store = await ContactStore.CreateOrOpenAsync(); var contact = await store.FindContactByIdAsync(Id); if (contact != null) { contact.FamilyName = "Zhao"; contact.GivenName = "Six"; await contact.SaveAsync(); } } catch (Exception e) { textblock1.Text = e.Message; } } //Delete contact async private Task Delete(string Id) { try { ContactStore store = await ContactStore.CreateOrOpenAsync(); await store.DeleteContactAsync(Id); } catch (Exception e) { textblock1.Text = e.Message; } } //Newly added private async void Button_Click_1(object sender, RoutedEventArgs e) { string[] familyNames = new string[] { "Zhao", "Money", "Sun", "Lee", "Week" }; string[] givenNames = new string[] {"Cloud","Right","Flying Swallow","White","Mr. 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(); } //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)); } }

Authors: Li Pan(Lipan)
Source: [Lipan] ()
Copyright statement: the copyright belongs to the author CO and garden blog. Shall indicate the reproduced with links, otherwise we will keep it shall be investigated for legal responsibility.
A: Windows phone 8 study notes location map navigation series directory a: no
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Reg at December 12, 2013 - 8:22 PM