Enables you to publish messages to proximate devices or subscribe to messages from proximate devices.
Syntax
var proximityDevice = Windows.Networking.Proximity.ProximityDevice;
Attributes
- DualApiPartitionAttribute()
- MarshalingBehaviorAttribute(Agile)
- StaticAttribute(Windows.Networking.Proximity.IProximityDeviceStatics, NTDDI_WIN8)
- ThreadingAttribute(Both)
- VersionAttribute(NTDDI_WIN8)
Members
The ProximityDevice class has these types of members:
Events
The ProximityDevice class has these events.
| Event | Description |
|---|---|
| DeviceArrived | Occurs when a device enters the proximate range. |
| DeviceDeparted | Occurs when a device leaves the proximate range. |
Methods
The ProximityDevice class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.
| Method | Description |
|---|---|
| FromId | Creates an instance of a ProximityDevice class and activates the specified proximity device interface. |
| GetDefault | Creates an instance of a ProximityDevice class and activates the default proximity provider. |
| GetDeviceSelector | Returns the class selection string that you can use to enumerate proximity devices. |
| PublishBinaryMessage(String, IBuffer) | Publishes a message that contains binary data to subscribers of the specified message type. |
| PublishBinaryMessage(String, IBuffer, MessageTransmittedHandler) | Publishes a message that contains binary data to subscribers of the specified message type. The specified handler is called when the message has been transmitted. |
| PublishMessage(String, String) | Publishes a message to subscribers of the specified message type. |
| PublishMessage(String, String, MessageTransmittedHandler) | Publishes a message to subscribers of the specified message type. The specified handler is called when the message has been transmitted. |
| PublishUriMessage(Uri) | Publishes a Uniform Resource Identifier (URI) to a proximate device. |
| PublishUriMessage(Uri, MessageTransmittedHandler) | Publishes a Uniform Resource Identifier (URI) to a proximate device. The specified handler is called when the message has been transmitted. |
| StopPublishingMessage | Stops publishing a message. |
| StopSubscribingForMessage | Cancels a message subscription. |
| SubscribeForMessage | Creates a subscription for a specified message type. |
Properties
The ProximityDevice class has these properties.
| Property | Access type | Description |
|---|---|---|
| Read-only | Gets the transfer rate of a proximity device. | |
| Read-only | Gets the DeviceInformation Id for a proximity device. | |
| Read-only | Gets the maximum size of a published message that this proximity device supports. |
Remarks
The ProximityDevice class enables applications to communicate with running applications on devices, typically within a range of 3 centimeters to4 centimeters.
You can create an instance of ProximityDeviceby using the GetDefault or FromId static method.
The ProximityDevice class uses publish/subscribe semantics and is useful for advertising and receiving small blocks of data. For larger amounts of data, or for persistent communications, use the PeerFinder and StreamSocket classes. For Windows Store apps, publications and subscriptions are active only if the calling app is in the foreground.
Examples
function id(elementId) { return document.getElementById(elementId); } var proximityDevice; function initializeProximityDevice() { proximityDevice = Windows.Networking.Proximity.ProximityDevice.getDefault(); if (proximityDevice) { proximityDevice.addEventListener("devicearrived", proximityDeviceArrived); proximityDevice.addEventListener("devicedeparted", proximityDeviceDeparted); id("messageDiv").innerHTML += "Proximity device initialized.<br />"; } else { id("messageDiv").innerHTML += "Failed to initialized proximity device.<br />"; } } function proximityDeviceArrived(device) { id("messageDiv").innerHTML += "Proximate device arrived. id = " + device.deviceId + "<br />"; } function proximityDeviceDeparted(device) { id("messageDiv").innerHTML += "Proximate device departed. id = " + device.deviceId + "<br />"; }
Requirements
|
Minimum supported client | Windows 8 [Windows Store apps, desktop apps] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps, desktop apps] |
|
Minimum supported phone | Windows Phone 8 |
|
Namespace |
|
|
Metadata |
|
|
Capabilities |
|
See also
Build date: 2/25/2013