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

MessageTransmittedHandler Delegate

描述在发布消息已传输时将处理引发事件的方法。

语法


Public Delegate Sub MessageTransmittedHandler( 
  sender As ProximityDevice,  
  messageId As Long 
)

特性

[Version(0x06020000)]

参数

sender

类型: ProximityDevice

发布消息的接近程度设备。

messageId

类型: Number [JavaScript] | System.Int64 [.NET] | int64 [C++]

消息的发布 ID。

备注

消息将继续发布,直到调用了 StopPublishingMessage 方法或者在发布计算机上释放了 ProximityDevice。消息被发送到已经订阅了相同消息类型的所有应用程序。

在使用 PublishMessage 方法时,仅支持的消息类型是从“Windows”中启动的一个。要使用另一消息类型发布消息,如“WindowsMime”或“NDEF:WriteTag”,则必须使用 PublishBinaryMessage 方法。

每当一条消息成功传输到设备后系统都会调用 MessageTransmittedHandler 委托,无论在该设备上有没有应用程序订阅到消息上。

示例


Private proximityDevice As Windows.Networking.Proximity.ProximityDevice
Private publishedMessageId As Long = -1
Private subscribedMessageId As Long = -1

Private Sub initializeProximityDevice()
    proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault()

    If proximityDevice IsNot Nothing Then
        AddHandler PublishMessageButton.Click, AddressOf PublishMessage
        AddHandler SubscribeForMessageButton.Click, AddressOf SubscribeForMessage
        AddHandler StopSubscribingForMessageButton.Click, AddressOf StopSubscribingForMessage
        AddHandler StopPublishingMessageButton.Click, AddressOf StopPublishingMessage
    Else
        WriteMessageText("Failed to initialized proximity device." & vbTab)
    End If
End Sub

Private Sub PublishMessage(sender As Object, e As RoutedEventArgs)
    ' Stop publishing the current message.
    If publishedMessageId <> -1 Then
        proximityDevice.StopPublishingMessage(publishedMessageId)
    End If

    publishedMessageId =
        proximityDevice.PublishMessage("Windows.SampleMessage", MessageTextBlock.Text,
                                       AddressOf MessagePublished)
End Sub

Private Sub MessagePublished(
sender As Windows.Networking.Proximity.ProximityDevice,
    messageId As Long)

' The message has been successfully published.
End Sub

Private Sub SubscribeForMessage(sender As Object, e As RoutedEventArgs)
    ' Only subscribe for the message one time.
    If subscribedMessageId = -1 Then
        subscribedMessageId =
        proximityDevice.SubscribeForMessage("Windows.SampleMessage", AddressOf messageReceived)
    End If
End Sub

Private Sub messageReceived(
    device As Windows.Networking.Proximity.ProximityDevice,
    message As Windows.Networking.Proximity.ProximityMessage)

    MessageBlock.Text &= "Message received: " & message.DataAsString & vbTab
End Sub

Private Sub StopSubscribingForMessage(sender As Object, e As RoutedEventArgs)
    proximityDevice.StopSubscribingForMessage(subscribedMessageId)
    subscribedMessageId = -1
End Sub

Private Sub StopPublishingMessage(sender As Object, e As RoutedEventArgs)
    proximityDevice.StopPublishingMessage(publishedMessageId)
    publishedMessageId = -1
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


要求

最低支持客户端

Windows 8

最低支持服务器

Windows Server 2012

最低支持电话

Windows Phone 8

命名空间

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

元数据

Windows.winmd

Capabilities

proximity
ID_CAP_PROXIMITY [Windows Phone]

另请参见

PublishMessage(String, String, MessageTransmittedHandler)
PublishBinaryMessage(String, IBuffer, MessageTransmittedHandler)
PublishUriMessage(Uri, MessageTransmittedHandler)
接近程度和轻击 (JavaScript)
接近程度和轻击 (C#/VB/C++)
示例
接近程度示例

 

 

显示:
© 2016 Microsoft