信息
您所需的主题如下所示。但此主题未包含在此库中。

ProximityMessage Class

表示从订阅收到的邮件。

语法


/* 有关创建或访问此对象的信息,请参见“备注”。 */

特性

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

成员

ProximityMessage类 具有这些类型的成员:

方法

The ProximityMessage 类 继承这些方法于:Object 类 (C#/VB/C++).

属性

ProximityMessage类 具有这些属性。

属性访问类型说明

Data

只读Gets the binary data of the message.

DataAsString

只读Gets the message data as text.

MessageType

只读Gets the type of the message.

SubscriptionId

只读Gets the subscription ID of the message.

 

备注

使用 PublishMessagePublishBinaryMessagePublishUriMessage 方法发布且由 MessageReceivedEventHandler(传递给 SubscribeForMessage 方法)接收的消息是 ProximityMessage 类型。

示例


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;
    }


要求

最低支持客户端

Windows 8 [Windows 应用商店应用程序, 桌面应用程序]

最低支持服务器

Windows Server 2012 [Windows 应用商店应用程序, 桌面应用程序]

最低支持电话

Windows Phone 8

命名空间

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

元数据

Windows.winmd

Capabilities

proximity
ID_CAP_PROXIMITY [Windows Phone]

另请参见

接近程度和轻击 (JavaScript)
接近程度和轻击 (C#/VB/C++)
示例
接近程度示例

 

 

显示: