ProximityDevice.DeviceArrived イベント
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
デバイスが近接範囲に入ると発生します。
public:
virtual event DeviceArrivedEventHandler ^ DeviceArrived;
// Register
event_token DeviceArrived(DeviceArrivedEventHandler const& handler) const;
// Revoke with event_token
void DeviceArrived(event_token const* cookie) const;
// Revoke with event_revoker
ProximityDevice::DeviceArrived_revoker DeviceArrived(auto_revoke_t, DeviceArrivedEventHandler const& handler) const;
public event DeviceArrivedEventHandler DeviceArrived;
function onDeviceArrived(eventArgs) { /* Your code */ }
proximityDevice.addEventListener("devicearrived", onDeviceArrived);
proximityDevice.removeEventListener("devicearrived", onDeviceArrived);
- or -
proximityDevice.ondevicearrived = onDeviceArrived;
Public Custom Event DeviceArrived As DeviceArrivedEventHandler
イベントの種類
Windows の要件
アプリの機能 |
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