Skip to main content
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.

Syntax


var number = proximityDevice.publishBinaryMessage(messageType, message, messageTransmittedHandler);

public long PublishBinaryMessage(
  string messageType, 
  IBuffer message, 
  MessageTransmittedHandler messageTransmittedHandler
)

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

public:
long long PublishBinaryMessage(
  String^ messageType, 
  IBuffer^ message, 
  MessageTransmittedHandler^ messageTransmittedHandler
)

Parameters

messageType

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

The type of message to deliver to subscribers.

message

Type: IBuffer

The binary message data to deliver to subscribers.

messageTransmittedHandler

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.

Remarks

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.

Important  

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.

Examples


Windows.Networking.Proximity.ProximityDevice proximityDevice;

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

if (proximityDevice != null)
    {
        // The format of the app launch string is: "<args>\tWindows\t<AppName>".
        // The string is tab or null delimited.

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

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

        string appName = Windows.ApplicationModel.Package.Current.Id.FamilyName + "!" + praid;

        string launchAppMessage = launchArgs + "\tWindows\t" + appName;

        var dataWriter = new Windows.Storage.Streams.DataWriter();
        dataWriter.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf16LE;
        dataWriter.WriteString(launchAppMessage);
        var launchAppPubId =
        proximityDevice.PublishBinaryMessage(
            "LaunchApp:WriteTag", dataWriter.DetachBuffer(), 
            proximityWriteTagLaunchAppMessageTransmitCallback);
    }
}

private void proximityWriteTagLaunchAppMessageTransmitCallback(
    Windows.Networking.Proximity.ProximityDevice sender,
    long messageId)
{
    // The LaunchApp message has been successfully written to a tag.
}

var proximityDevice;

function publishLaunchApp() {
    proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();

if (proximityDevice) {
        // The format of the app launch string is: "<args>\tWindows\t<AppName>".
        // The string is tab or null delimited.

        // The <args> string can be an empty string ("").
        var launchArgs = "user=default";

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

        var appName = Windows.ApplicationModel.Package.current.id.familyName + "!" + praid;

        var launchAppMessage = launchArgs + "\tWindows\t" + appName;

        var dataWriter = new Windows.Storage.Streams.DataWriter();
        dataWriter.unicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.utf16LE;
        dataWriter.writeString(launchAppMessage);
        var launchAppPubId =
             proximityDevice.publishBinaryMessage(
                 "LaunchApp:WriteTag", 
                 dataWriter.detachBuffer(), 
                 proximityWriteTagLaunchAppMessageTransmitCallback);
     }
}

function proximityWriteTagLaunchAppMessageTransmitCallback() {
    // The LaunchApp message has been successfully written to a tag.
}

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
        dataWriter.WriteString(launchAppMessage)
        Dim launchAppPubId =
           proximityDevice.PublishBinaryMessage(
              "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

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8

Namespace

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

Metadata

Windows.winmd

Capabilities

proximity
ID_CAP_PROXIMITY [Windows Phone]

See also

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