ProximityDevice.PublishBinaryMessage(String, IBuffer, MessageTransmittedHandler) | publishBinaryMessage(String, IBuffer, MessageTransmittedHandler) method

Applies to Windows and Windows Phone

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.


Public Function PublishBinaryMessage(
  messageType As String,  
  message As IBuffer,  
  messageTransmittedHandler As MessageTransmittedHandler 
) As Long



Type: String [JavaScript] | System.String [.NET] | Platform::String [C++]

The type of message to deliver to subscribers.


Type: IBuffer

The binary message data to deliver to subscribers.


Type: MessageTransmittedHandler

The handler to call when the message has been transmitted.

Return value

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

A unique publication ID for the published message.


You can publish multiple messages of the same message type and each publication will have a unique ID associated with it.

You can stop publishing a message by passing the publication ID returned by the PublishBinaryMessage method to the StopPublishingMessage method.

Messages continue to be published until the StopPublishingMessage method is called or the ProximityDevice is released.

You can subscribe to published messages using the SubscribeForMessage method.

For details on the types of messages that you can publish with the PublishBinaryMessage(String, IBuffer, MessageTransmittedHandler) method, see the remarks in the PublishBinaryMessage(String, IBuffer) reference topic.

You can use the PublishMessage method to publish a text message to a proximate computer. You can use the PublishUriMessage method to publish a Uniform Resource Identifier (URI) to a proximate computer.


The proximity APIs do not provide authentication, encryption, or message integrity. Do not use proximity to exchange user sensitive information such as passwords, financial data, text messages, email, photographs, or government id numbers.


Private proximityDevice As Windows.Networking.Proximity.ProximityDevice

Private Sub PublishLaunchApp()
    proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault()
   If proximityDevice IsNot Nothing Then
        ' The format of the app launch string is: "<args>" & vbTab & "Windows" vbTab & "<AppName>".
        ' The string is tab or null delimited.

        ' The <args> string can be an empty string ("").
        Dim launchArgs = "user=default"

        ' The format of the AppName is: PackageFamilyName!PRAID.
        Dim praid = "MyAppId" ' The Application Id value from your package.appxmanifest.

        Dim appName = Windows.ApplicationModel.Package.Current.Id.FamilyName & "!" & praid

        Dim launchAppMessage = launchArgs & vbTab & "Windows" & vbTab & appName

        Dim dataWriter = New Windows.Storage.Streams.DataWriter()
        dataWriter.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf16LE
        Dim launchAppPubId =
              "LaunchApp:WriteTag", dataWriter.DetachBuffer(),
              AddressOf proximityWriteTagLaunchAppMessageTransmitCallback)
    End If
End Sub

Private Sub proximityWriteTagLaunchAppMessageTransmitCallback(
    sender As Windows.Networking.Proximity.ProximityDevice,
    messageId As Long)
    ' The LaunchApp message has been successfully written to a tag.
End Sub


Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8


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




ID_CAP_PROXIMITY [Windows Phone]

See also

PublishBinaryMessage(String, IBuffer)
Proximity and Tapping (JavaScript)
Proximity and Tapping (C#/VB/C++)
Proximity sample



© 2014 Microsoft