ProximityDevice 클래스

정의

디바이스에 근접하는 메시지를 게시하거나 근접 디바이스의 메시지를 구독할 수 있습니다.

public ref class ProximityDevice sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class ProximityDevice final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class ProximityDevice
Public NotInheritable Class ProximityDevice
상속
Object Platform::Object IInspectable ProximityDevice
특성

Windows 요구 사항

디바이스 패밀리
Windows 10 (10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox에서 도입되었습니다.)
API contract
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)
앱 기능
ID_CAP_PROXIMITY [Windows Phone] proximity ID_CAP_PROXIMITY [Windows Phone]

예제

Windows.Networking.Proximity.ProximityDevice proximityDevice;

private void InitializeProximityDevice()
{
    proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();

    if (proximityDevice != null) {
        proximityDevice.DeviceArrived += ProximityDeviceArrived;
        proximityDevice.DeviceDeparted += ProximityDeviceDeparted;

        WriteMessageText("Proximity device initialized.\n");
    }
    else
    {
        WriteMessageText("Failed to initialized proximity device.\n");
    }
}

private void ProximityDeviceArrived(Windows.Networking.Proximity.ProximityDevice device)
{
    WriteMessageText("Proximate device arrived. id = " + device.DeviceId + "\n");
}

private void ProximityDeviceDeparted(Windows.Networking.Proximity.ProximityDevice device)
{
    WriteMessageText("Proximate device departed. id = " + device.DeviceId + "\n");
}

// Write a message to MessageBlock on the UI thread.
private Windows.UI.Core.CoreDispatcher messageDispatcher = Window.Current.CoreWindow.Dispatcher;

async private void WriteMessageText(string message, bool overwrite = false)
{
    await messageDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
        () =>
        {
            if (overwrite)
                MessageBlock.Text = message;
            else
                MessageBlock.Text += message;
        });
}
Dim proximityDevice As Windows.Networking.Proximity.ProximityDevice

Private Sub InitializeProximityDevice()

    proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault()

    If proximityDevice IsNot Nothing Then
        AddHandler proximityDevice.DeviceArrived, AddressOf ProximityDeviceArrived
        AddHandler proximityDevice.DeviceDeparted, AddressOf ProximityDeviceDeparted

        WriteMessageText("Proximity device initialized." & vbTab)
    Else
        WriteMessageText("Failed to initialized proximity device." & vbTab)
    End If
End Sub

Private Sub ProximityDeviceArrived(device As Windows.Networking.Proximity.ProximityDevice)
    WriteMessageText("Proximate device arrived. id = " & device.DeviceId & vbTab)
End Sub

Private Sub ProximityDeviceDeparted(device As Windows.Networking.Proximity.ProximityDevice)
    WriteMessageText("Proximate device departed. id = " & device.DeviceId & vbTab)
End Sub

' Write a message to MessageBlock on the UI thread.
Private Async Sub WriteMessageText(message As String, Optional overwrite As Boolean = False)
    Await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
        Sub()
            If overwrite Then
                MessageBlock.Text = message
            Else
                MessageBlock.Text &= message
            End If
        End Sub)
End Sub

설명

ProximityDevice 클래스를 사용하면 애플리케이션이 일반적으로 3cm~4센티미터 범위 내에서 디바이스에서 실행 중인 애플리케이션과 통신할 수 있습니다.

GetDefault 또는 FromId 정적 메서드를 사용하여 ProximityDevice의 instance 만들 수 있습니다.

ProximityDevice 클래스는 게시/구독 의미 체계를 사용하며 작은 데이터 블록을 광고하고 받는 데 유용합니다. 더 많은 양의 데이터 또는 영구 통신의 경우 PeerFinderStreamSocket 클래스를 사용합니다. UWP 앱의 경우 호출 앱이 포그라운드에 있는 경우에만 게시 및 구독이 활성화됩니다.

중요

근접 API는 인증, 암호화 또는 메시지 무결성을 제공하지 않습니다. 근접성을 사용하여 암호, 재무 데이터, 문자 메시지, 이메일, 사진 또는 정부 ID 번호와 같은 사용자 중요한 정보를 교환하지 마세요.

속성

BitsPerSecond

근접 디바이스의 전송 속도를 가져옵니다.

DeviceId

근접 디바이스의 DeviceInformation ID 를 가져옵니다.

MaxMessageBytes

이 근접 디바이스에서 지원하는 게시된 메시지의 최대 크기를 가져옵니다.

메서드

FromId(String)

ProximityDevice 클래스의 instance 만들고 지정된 근접 디바이스 인터페이스를 활성화합니다.

GetDefault()

ProximityDevice 클래스의 instance 만들고 기본 근접 공급자를 활성화합니다.

GetDeviceSelector()

근접 디바이스를 열거하는 데 사용할 수 있는 클래스 선택 문자열을 반환합니다.

PublishBinaryMessage(String, IBuffer)

지정된 메시지 형식의 구독자에게 이진 데이터가 포함된 메시지를 게시합니다.

PublishBinaryMessage(String, IBuffer, MessageTransmittedHandler)

지정된 메시지 유형의 구독자에게 이진 데이터가 포함된 메시지를 게시합니다. 지정된 처리기는 메시지가 전송될 때 호출됩니다.

PublishMessage(String, String)

지정된 메시지 유형의 구독자에게 메시지를 게시합니다.

PublishMessage(String, String, MessageTransmittedHandler)

지정된 메시지 유형의 구독자에게 메시지를 게시합니다. 지정된 처리기는 메시지가 전송될 때 호출됩니다.

PublishUriMessage(Uri)

근접 디바이스에 URI(Uniform Resource Identifier)를 게시합니다.

PublishUriMessage(Uri, MessageTransmittedHandler)

근접 디바이스에 URI(Uniform Resource Identifier)를 게시합니다. 지정된 처리기는 메시지가 전송될 때 호출됩니다.

StopPublishingMessage(Int64)

메시지 게시를 중지합니다.

StopSubscribingForMessage(Int64)

메시지 구독을 취소합니다.

SubscribeForMessage(String, MessageReceivedHandler)

지정된 메시지 유형에 대한 구독을 만듭니다.

이벤트

DeviceArrived

디바이스가 근접 범위에 들어갈 때 발생합니다.

DeviceDeparted

디바이스가 근접 범위를 벗어나면 발생합니다.

적용 대상

추가 정보