Export (0) Print
Expand All
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.

ProximityMessage class

Applies to Windows and Windows Phone

Represents a message that's received from a subscription.

Syntax


/* For information about creating or accessing this object, see Remarks. */

Attributes

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

Members

The ProximityMessage class has these types of members:

Methods

The ProximityMessage class inherits methods from the Object class (C#/VB/C++).

Properties

The ProximityMessage class has these properties.

PropertyAccess typeDescription

Data

Read-onlyGets the binary data of the message.

DataAsString

Read-onlyGets the message data as text.

MessageType

Read-onlyGets the type of the message.

SubscriptionId

Read-onlyGets the subscription ID of the message.

 

Remarks

Messages published using the PublishMessage, PublishBinaryMessage, or PublishUriMessage methods and received by the MessageReceivedEventHandler passed to the SubscribeForMessage method are of type ProximityMessage.

Examples


function id(elementId) {
    return document.getElementById(elementId);
}

var proximityDevice;
var publishedMessageId = -1;
var subscribedMessageId = -1;

function initializeProximityDevice() {
    proximityDevice = Windows.Networking.Proximity.ProximityDevice.getDefault();

    if (proximityDevice) {
        id("publishMessageButton").addEventListener("click", publishMessage);
        id("subscribeForMessageButton").addEventListener("click", subscribeForMessage);
id("stopSubscribingForMessageButton").addEventListener("click", 
    stopSubScribingForMessage);
id("stopPublishingMessageButton").addEventListener("click", 
    stopPublishingMessage);
    }
    else {
        id("messageDiv").innerHTML += "Failed to initialized proximity device.<br />";
    }
}

function publishMessage() {
    // Stop publishing the current message.
    if (publishedMessageId != -1) {
        proximityDevice.stopPublishingMessage(publishedMessageId);
    }

    publishedMessageId = 
proximityDevice.publishMessage("Windows.SampleMessage", id("messageText").value);
}

function subscribeForMessage() {
    // Only subscribe for the message one time.
    if (subscribedMessageId === -1) {
        subscribedMessageId = 
    proximityDevice.subscribeForMessage("Windows.SampleMessage", messageReceived);
    }
}

function messageReceived(device, message) {
    id("messageDiv").innerHTML += "Message received: " + message.dataAsString + "<br />";
}

    function stopSubscribingForMessage() {
proximityDevice.stopSubscribingForMessage(subscribedMessageId);
    subscribedMessageId = -1;
    }

    function stopPublishingMessage() {
proximityDevice.stopPublishingMessage(publishedMessageId);
    publishedMessageId = -1;
    }


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