Design and Development of Windows 8 Metro-tile and notification (2)

Source: Internet
Author: User
Add screen lock notification

Tile notification EnabledMetroThe application can update the tile content, including the primary tile and secondary tile, even if the application is not currently running. Screen lock notification is a special tile notification, which updates the tile.Screen lock reminder, Which is displayed from the predefined position on the tile0-99Or a special symbol (for example*). Screen lock notification SourceWindowsThe response of the notification service to the cloud-based service call of the application. In this exerciseContosocookbookAdd a simple screen lock notification to notify users when there are new recipes.

Task1-Modify the Application List File

MicrosoftAContoso cookbookYou can call and subscribe to the screen lock notification.Windows azureService, andWNsDeliver notifications. When a service is deployed, it is configured (Contoso. To receive the screen lock notification sent by this service, you need to modify the Application List file and use the correct package name and issuerID.

1.In Solution Explorer, double-clickPackage. appxmanifestOpen the configuration file.

2.In the configuration Editor, click"PackagingTab.

3.SetPackage nameChange to"Build.55aac983-908e-4a91-8d5f-ce6cf8d3125e".

4.SetPublisher display nameChange to"Contoso".

5. click " publisher " choose certificate "in the row. Select configurecertificate from the " selectfrom file... and select contoso. pfx in the confirmation dialog box ". contoso. pfx is in the certs folder of the original material. Click OK .

6.ConfirmPackage name,Publisher,Publisherdisplay nameContent,3.



Figure3

Edited list

7.Save changes and disablePackage. appxmanifest.

 

Task2-Subscribe to screen lock notification

To subscribe to screen lock notification,MetroThe application must beMetroGet a notification channel at runtime andUriTo the service. When the Service wants to update the screen lock reminder, it uses the channelUriCallWNs,WNsThe screen lock notification will be sent to the application. We are goingContosocookbookGet a channel at startupUriAnd use it to subscribe to the screen lock notification.

1.OpenDefault. js, FindApp. onactivatedFunction.

2.Next to the comment"Initialize your applicationhereThen, add the following statement to the function to subscribe to the screen lock Notification every time the application starts:

Javascript

// Register for badgenotification

Windows. Networking. pushnotifications. pushnotifchanchannelmanager. createpushicationchanchannelforapplicationasync (). Then (function (Channel ){

// Base-64 encode the channel URI so it can be passed in a query string

Varwsc = windows. Security. cryptography;

VaR buffer = WSC. cryptographicbuffer. convertstringtobinary (Channel. Uri, WSC. binarystringencoding. utf8 );

Varuri = WSC. cryptographicbuffer. encodetobase64string (buffer );

 

// Pass the encoded channel URI to the contoso cookbook Service

Winjs. xhr ({URL: "http://ContosoRecipes8.cloudapp.net? Uri = "+ URI}). Then (function (xhr ){

If (xhr. Status <200 | xhr. Status> = 300 ){

VaR dialog = new windows. UI. popups. messagedialog ("unable to openpush notification channel ");

Dialog. showasync ();

}

});

});

Note:PairCreatepushnotifchanchannelforapplicationasyncFromMetroRequest a notification channel. In this exampleBase-64Peer ChannelUriEncoding to enableUriDeliver to recipe service.Base-64Encoding times are not required, but they can preventUriContains some strings to be queried.Base-64Encoding possibilities.

winjs. xhr is used to call the recipe Service hosted on windowsazure , and transfer the channel URI . This Service keeps a record of all clients that have subscribed to its service ( URI , within an hour, a screen lock Notification is triggered every 60 seconds to these clients. Each channel URI that is passed to the service represents a specific application running on a specific device. The Service performs the "Remove redundant" Operation on the channel uril , so that if contosocookbook repeatedly transmits the same channel URI , no more screen lock reminders will be received. If the service receives the same channel URI , the channel is refreshed, in this way, the corresponding application will continue to receive the screen lock notification within the next 60 minutes.

3.TheCodeAdd the following statement to clear the screen lock Notification every time the application starts:

Javascript

// Clear the badge

Windows. UI. Events. badgeupdatemanager. createbadgeupdaterforapplication (). Clear ();

Note:After the application receives the screen lock notification, a number appears on the application's primary tile. By default, this number (or name)Screen lock reminder) Will never disappear. Use the newly added statementWindowsRunningBadgeupdater. ClearMethod to clear the screen lock notification on the tile. Because the application can receive screen lock notification without running the application, you can test the screen lock notification without running the application. To clear the screen lock notification, you only need to run the application again.

 

Task3-Test lock screen notification

The last step is to ensure that the application receives the screen lock notification sent to it.

1.PressF5Start the application in the debuggerProgram. During the current startup process, the application will subscribe to the screen lock notification.

2.ReturnVisual StudioStop debugging and disable the application.

3.BackMetroStart the screen and find the application's primary tile.

4.Observe the tile for a period of time. In60Within seconds, a number should appear above,4. Conceptually, this number indicates the number of new recipes available. In reality, it is only the number of minutes in the past hour.



Figure4

Screen lock notification displayed on the primary Tile

5.Continue to observe the tile2-3Minutes, confirm the screen lock reminder every60Seconds.

6.SlaveVisual StudioRun the application again.

7.BackMetroStart the screen and confirm that the screen lock reminder has disappeared from the tile. (Next60It will appear again within seconds, but the screen lock reminder disappears, indicating that the application is executed every time it is started.Badgeupdater. ClearThe call takes effect .)

8.ReturnVisual StudioAnd stop debugging.

Note: ThisArticleThis is the script for Windows 8 online lab on msdn. It is for your reference only. If you want to experience the complete experiment, click the msdn online lab below

Http://msdn.microsoft.com/zh-cn/hh968278

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.