The previous article described how to customize the protocol for the application, so a friend would ask, I want to register multiple protocols for my app, different protocols to handle different things, can I? The answer is yes.
method is mainly on the configuration manifest file, here I give an example, the sample application will register two protocols, respectively, music: and Video:.
Locate the Package/applications/application node in the manifest file, add the Extensions node under the application element, represent an extension of the application declaration, and can contain n uap:extension elements. Be sure to add the UAP prefix to indicate that it is for general purpose applications. It is with the uap:extension element that it is possible to define multiple protocols for an application, but be sure to remember that a uap:extension element can only declare one protocol .
Since multiple protocols are needed, define multiple uap:extension elements, as in this example the manifest file is defined as follows:
<Extensions> <uap:extensionCategory= "Windows.protocol"> <Uap:protocolName= "Music"/> </uap:extension> <uap:extensionCategory= "Windows.protocol"> <Uap:protocolName= "Video"/> </uap:extension> </Extensions>
The name attribute of the protocol element specifies the names of the protocols.
The next step in the App class is to override the Onactivated method by removing the URI of the active application from the parameter and then determining which protocol the application was activated by.
protected Override voidOnActivated (Iactivatedeventargs args) {if(args. Kind = =activationkind.protocol) {Protocolactivatedeventargs parg=(Protocolactivatedeventargs) args; Uri URI=parg. Uri; stringdata =NULL; //determine which protocol is active Switch(URI. Scheme) { Case "Music": Data="Music"; Break; Case "Video": Data="Video"; Break; default: Data=NULL; Break; } //Show PageFrame Rootframe = Window.Current.Content asFrame; if(Rootframe = =NULL) {Rootframe=NewFrame (); Window.Current.Content=Rootframe; } rootframe. Navigate (typeof(MainPage), data); } Window.Current.Activate (); }
Args. The value of kind is critical because the application may be activated by other means, such as file associations, so it must be judged here. Once the URI is obtained, the scheme attribute can get the schema name of the URI, which is the name of the protocol, such as music, video, as defined above. It then determines which protocol activates the application.
Next, write a sample application to activate the above application via protocol, and in code you can start a URI with the Launchuriasync method of the Launcher class.
New Uri (txt1. Text); await Windows.System.Launcher.LaunchUriAsync (URI);
The test results are as shown.
Note that when using the Protocol, the protocol name must be appended with a colon (in English), such as music:.
Example: Http://files.cnblogs.com/files/tcjiaan/protocol-part2.zip
"WIN10 Application Development" protocol-NEXT: Customizing multiple protocols