1 / 10

Universal APIs

Universal APIs. Windows Phone 8.x + Windows 8.x. Windows.Networking.Proximity.ProximityDevice. “Makes your app able to communicate with other devices within an approximate range of 3–4 centimeters, and exchange a small payload of data during the tap .”. ProximityDevice - Receiving.

jethro
Download Presentation

Universal APIs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Universal APIs Windows Phone 8.x + Windows 8.x

  2. Windows.Networking.Proximity.ProximityDevice “Makes your app able to communicate with other devices within an approximate range of 3–4 centimeters, and exchange a small payload of data during the tap.”

  3. ProximityDevice - Receiving ProximityDevice device = ProximityDevice.GetDefault(); // Make sure NFC is supported if (device!= null) { long Id = device.SubscribeForMessage ("Windows.SampleMessageType", messageReceived); Debug.WriteLine("Published Message. ID is {0}", Id); // Store the unique message Id so that it // can be used to stop subscribing for this message type } private void messageReceived(ProximityDevice sender, ProximityMessage message) { Debug.WriteLine("Received from {0}:'{1}'", sender.DeviceId, message.DataAsString); }

  4. ProximityDevice - Sending

  5. Windows.Networking.Proximity.PeerFinder “Lets you discover another instance of your app on a nearby device and create a socket connection between the peer apps by using a tap gesture, or by browsing. A peer app is another instance of an app that is running on another device.”

  6. PeerFinder – Finding other Windows Phone peers ProximityDevice device = ProximityDevice.GetDefault(); // Make sure NFC is supported if (device!= null) { PeerFinder.TriggeredConnectionStateChanged += OnTriggeredConnectionStateChanged; // Start finding peer apps, while making this app discoverable by peers PeerFinder.Start(); }

  7. PeerFinder – Finding other Windows Phone peers StreamSocket _streamSocket; void OnTriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgsargs) { switch (args.State) { case TriggeredConnectState.Listening: // Connecting as host break; case TriggeredConnectState.PeerFound: // Proximity gesture is complete and user can pull their devices away. // Remaining work is to establish the connection using a different //transport, like TCP/IP or Bluetooth break;

  8. PeerFinder – Finding other Windows Phone peers case TriggeredConnectState.Connecting: // Connecting as a client break; case TriggeredConnectState.Completed: // Connection completed, retrieve the socket over which to communicate _streamSocket = args.Socket; break; case TriggeredConnectState.Canceled: break; case TriggeredConnectState.Failed: // Connection was unsuccessful break; } }

More Related