Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ProximityDevice class

Applies to Windows and Windows Phone

Enables you to publish messages to proximate devices or subscribe to messages from proximate devices.

Syntax


var proximityDevice = Windows.Networking.Proximity.ProximityDevice;

Attributes

[DualApiPartition()]
[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]

Members

The ProximityDevice class has these types of members:

Events

The ProximityDevice class has these events.

EventDescription
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.

MethodDescription
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.

PropertyAccess typeDescription

BitsPerSecond

Read-onlyGets the transfer rate of a proximity device.

DeviceId

Read-onlyGets the DeviceInformation Id for a proximity device.

MaxMessageBytes

Read-onlyGets 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 to 4 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.

Important  

The proximity APIs do not provide authentication, encryption, or message integrity. Do not use proximity to exchange user sensitive information such as passwords, financial data, text messages, email, photographs, or government id numbers.

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

Windows.Networking.Proximity
Windows::Networking::Proximity [C++]

Metadata

Windows.winmd

Capabilities

proximity
ID_CAP_PROXIMITY [Windows Phone]

See also

Proximity and Tapping (JavaScript)
Proximity and Tapping (C#/VB/C++)
Samples
Proximity sample

 

 

Show:
© 2014 Microsoft