Windows.Networking.Proximity Namespace

包含支持近距离设备之间连接的类。

成员

Windows.Networking.Proximity命名空间 具有这些类型的成员:

Windows.Networking.Proximity命名空间 具有这些类。

说明
ConnectionRequestedEventArgs Contains properties that are passed to an application with the ConnectionRequested event.
PeerFinder Enables you to discover another instance of your app on a nearby device and create a socket connection between the peer apps by using a tap gesture or by browsing.
PeerInformation Contains information that identifies a peer.
PeerWatcher Dynamically discovers peer apps within wireless range.
ProximityDevice Enables you to publish messages to proximate devices or subscribe to messages from proximate devices.
ProximityMessage Represents a message that's received from a subscription.
TriggeredConnectionStateChangedEventArgs Contains properties that the TriggeredConnectionStateChanged event passes to an application.

 

委托

Windows.Networking.Proximity命名空间 具有这些委托。

委托说明
DeviceArrivedEventHandler Describes the method that handles the DeviceArrived event.
DeviceDepartedEventHandler Describes the method that handles the DeviceDeparted event.
MessageReceivedHandler Describes the method that will handle the event that's fired when a message that has been subscribed to has been received.
MessageTransmittedHandler Describes the method that will handle the event that's fired when a published message has been transmitted.

 

枚举

Windows.Networking.Proximity命名空间 具有这些枚举。

Enumeration说明
PeerDiscoveryTypes Indicates which discovery options are available to use with the PeerFinder class.
PeerRole Describes the role of the peer app when connected to multiple peers.
PeerWatcherStatus Describes the status of a PeerWatcher object.
TriggeredConnectState Indicates the current state of a connection to a peer application.

 

备注

通过使用简单的触控笔势,可以使用接近程度连接计算机。如果两台计算机彼此相距 3 至 4 厘米,则每台计算机的操作系统会检测到另一台计算机。然后可以连接两台计算机来共享目录或发布并订阅消息。接近程度还通过 Wi-Fi Direct 支持发现对等设备。

重要事项  

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

示例

此示例显示如何使用 ProximityDevice 类确定设备何时进入和离开接近程度。


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 Server 2012

最低支持电话

Windows Phone 8

命名空间

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

元数据

Windows.winmd

Capabilities

proximity
ID_CAP_PROXIMITY [Windows Phone]

另请参见

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

 

 

显示:
© 2014 Microsoft