导出 (0) 打印
全部展开
信息
您所需的主题如下所示。但此主题未包含在此库中。

ProximityDevice Class

使您可以向接近程度设备发布消息或从接近程度设备中订阅消息。

语法


var proximityDevice = Windows.Networking.Proximity.ProximityDevice;

特性

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

成员

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

事件

ProximityDevice类 具有这些事件。

事件说明
DeviceArrived Occurs when a device enters the proximate range.
DeviceDeparted Occurs when a device leaves the proximate range.

 

方法

The ProximityDevice 类 具有这些方法。 对于 C#、Visual Basic 和 C++,它还继承方法于Object 类.

方法说明
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.

 

属性

ProximityDevice类 具有这些属性。

属性访问类型说明

BitsPerSecond

只读Gets the transfer rate of a proximity device.

DeviceId

只读Gets the DeviceInformation Id for a proximity device.

MaxMessageBytes

只读Gets the maximum size of a published message that this proximity device supports.

 

备注

ProximityDevice 项可以让应用程序与设备上运行的应用程序进行通信,通常在 3 厘米到 4 厘米的范围内。

可以使用 GetDefaultFromId 静态方法创建 ProximityDevice实例。

ProximityDevice 类使用发布/订阅语义并且对播放和接收小数据块十分有用。对于更大量的数据,或对于持久通信,请使用 PeerFinderStreamSocket 类。 对于 Windows Store 应用程序,发布和订阅仅在调用程序位于前景中时才处于活动状态。

重要事项  

邻近 API 不提供身份验证、加密或消息的完整性。不要使用邻近感应来交换用户敏感信息,如密码、财务数据、文本消息、电子邮件、照片或身份证号码。

示例


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


要求

最低支持客户端

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++)
示例
接近程度示例

 

 

显示:
© 2015 Microsoft