Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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);

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


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.
}


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

 

 

Show:
© 2014 Microsoft