"Win 10 application Development" launches applications on remote devices

Source: Internet
Author: User

This feature must be available in the system version above the "Redstone 1" (Build 14393), which runs on one device, and can be used by URIs to launch apps on another device. Activating a remote application requires the following prerequisites:

    • The system must be build 14393 or later, and UWP apps must be developed with SDK version 14393 or later.
    • Applications that are launched should support protocol activation, such as Cortana's protocol URI: "Ms-cortana:", of course, if you develop your own application, you can define a protocol, the name is random, not with the system protocol or other people's application conflict, such as: "Haha:" " ZXZX: "And so on.
    • A device that must be signed in with the same Microsoft account. That is, the device that is logged on with the same MS account is available. This function to ensure a certain degree of security, certainly can not let you any device can be connected, the application becomes a Trojan horse.

There is no limit to the type of setup, as long as the Windows 10 system running "Redstone" or above is on line, including PCs, tablets, hubs, phones, XBox, notebooks, Iot, holographic virtualization devices ... If it is installed in the virtual machine system, with MS account login can be, as long as the win 10, whatever device you can play.

is not very tall, the following old weeks to talk about how to play, the usual, or first to understand the method.

We need to use two namespaces, the class you want to use, from the two namespaces to find the line, you must learn to use the "Object Browser" window.

    • Windows.system
    • Windows.System.RemoteSystems

Look at the name, remote System, you can guess seven points, and it's definitely about the long-distance call.

To invoke an app on a remote device, you first need to identify these devices, and the SDK provides two ways to do so. The first method is relatively simple, directly through the device name to find, call Remotesystem.findbyhostnameasync (HostName) static method, specify the device name to find, if found, return a Remotesystem instance (can wait asynchronously). The Remotesystem class encapsulates remote system-related information, which is not informative, but is a computer name and an ID value that can be used to uniquely identify the device.

The second method works a bit large, it is by creating a Remotesystemwatcher object, and then using this object to monitor the connection of the remote device, if the device is found, the remotesystemadded event occurs, If a device is removed (MS Account no longer logs on to the device and the device is removed from the device Management webpage) The Remotesystemremoved event is raised.

To turn on monitoring, call the Start method and call the Stop method to stop.

When you create a Remotesystemwatcher object, you can pass several filters to the Remotesystem.createwatcher method to determine the lookup range. The filter class implements the Iremotesystemfilter interface.

The optional filters can have these:

    • Remotesystemkindfilter: Filter By device type, such as desktop, phone, Xbox, etc., this string can be obtained from the static properties of the Remotesystemkinds class.
    • Remotesystemdiscoverytypefilter: Filter By Discovery scope, rules are defined by Remotesystemdiscoverytype enumeration, any represents unrestricted range, Proximal said that through the intranet or Bluetooth can be connected to the range to find, Cloud is the cloud recording device, is the MS account login device. Of course the big advance is that these devices are logged in with Ms Account and are in use.
    • Remotesystemstatustypefilter: Filtered by the current state of the device, that is, whether the device is currently in a connected state.

After locating the remote device, use the Remotesystem instance to create an Remotesystemconnectionrequest instance, as it is used when activating the application.

Finally, the Remotesystemconnectionrequest instance that you just created is passed to the Remotelauncher class with the URI that you want to launch the application to, and you can start the application on the remote device with the Launchuriasync method.

Below, the actual combat.

This example is not complex, first scan the available remote devices (PC, phone, tablet, game console kill), then select a device, and eventually start the "calculator" app on the target device. The protocol URI for the UWP calculator is: "Calculator:" (not including "").

First, look for the device.

varReqres =awaitRemotesystem.requestaccessasync (); if(Reqres! =remotesystemaccessstatus.allowed) {btnlaunch.isenabled=false; return; } List<IRemoteSystemFilter> filterlist =NewList<iremotesystemfilter>(); Remotesystemdiscoverytypefilter FT1=NewRemotesystemdiscoverytypefilter (Remotesystemdiscoverytype.any); string[] kinds ={remotesystemkinds.desktop, Remotesystemkinds.phone, remotes            Ystemkinds.xbox}; Remotesystemkindfilter ft2=Newremotesystemkindfilter (kinds);            Filterlist.add (FT1);            Filterlist.add (ft2); Watcher=Remotesystem.createwatcher (filterlist); Watcher. remotesystemadded+=remotesystem_added; Watcher. Remotesystemremoved+=remotesystem_removed; Watcher. Start ();

Note that before any lookup operations are made, you must first call the Requestaccessasync method, determine that the system allows you to operate, otherwise it is a white busy.

The following code deals with the two events of watcher.

Private Async voidremotesystem_removed (remotesystemwatcher sender, Remotesystemremovedeventargs args) {awaitDispatcher.runasync (Windows.UI.Core.CoreDispatcherPriority.Normal, () ={remotesystem sys= Remotesystems.firstordefault (r = r.id = =args.                 REMOTESYSTEMID); if(SYS! =NULL) {remotesystems.remove (SYS);        }             }); }        Private Async voidremotesystem_added (remotesystemwatcher sender, Remotesystemaddedeventargs args) {awaitDispatcher.runasync (Windows.UI.Core.CoreDispatcherPriority.Normal, () ={remotesystems.add (args.            Remotesystem);        }); }

You can now start the calculator on the selected device.

if(LV. SelectedIndex = =-1)return; Btnlaunch.isenabled=false; Remotesystem Rmsys= Lv. SelectedItem asRemotesystem; Uri Remoteuri=NewUri ("Calculator:"); Remotesystemconnectionrequest Request=Newremotesystemconnectionrequest (Rmsys); varR =awaitRemotelauncher.launchuriasync (Request, Remoteuri); Btnlaunch.isenabled=true;

A key step is to configure the manifest file, if not configured, without permission.

Device features that support remote systems are declared in the XML namespace of version 3, so they are introduced first.

xmlns:uap3= "HTTP://SCHEMAS.MICROSOFT.COM/APPX/MANIFEST/UAP/WINDOWS10/3"

Give it a prefix called UAP3, which is handy for referencing later. Then declare the relevant capability.

< Capabilities >    <  name= "internetclient"/>    <Name  = "Remotesystem"/>  </capabilities> 

OK, everything is ready, start the other device (or the system in the virtual machine) first.

Then go back to the development machine, run the app, and it will find the device you've logged in to.

Select a device in the list, click the button below, and if no natural disaster occurs, the Calculator app on your other device will start. Such as.

Well, today's topic is discussed here.

Sample code

"Win 10 application Development" launches applications on remote devices

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.