Export (0) Print
Expand All
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) | publishBinaryMessage(String, IBuffer) method

Applies to Windows and Windows Phone

Publishes a message that contains binary data to subscribers of the specified message type.

Syntax


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

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.

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.

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.

Message Types

You use the messageType parameter to supply an identifier that uniquely identifies the published message, and also defines the meaning of the message and the intended subscriber audience.

Message type values are case-sensitive strings that consist of two parts: the protocol and the subtype. The protocol is first, followed by a dot (.) and then the subtype. The subtype is a string of alphanumeric characters and any of the valid URI characters as defined by RFC 3986: - . _~ : / ? # [ ] @ ! $ & ‘ ( ) * + , ; = %. The subtype cannot exceed a length of 250 characters. The following table shows the supported values for the protocol part of the message type.

Windows

The message contains binary data.

WindowsUri

The message data contains a UTF-16LE encoded string that is a URI.

Windows will always handle "WindowsUri" messages by prompting the user to view a received URI that in the Windows default app that handles a specific URI protocol, for example, http:// URIs open in the default web browser. Windows will open a URI in the default app even if another app is also subscribed to "WindowsUri".

Instead of calling the PublishBinaryMessage method with this protocol, use the PublishUriMessage method.

If you publish a Uri to a computer that is not running Windows, the Uri is automatically formatted based on the proximity technology that your computer supports. For example, if your computer uses NFC hardware for proximity, then the Uri is formatted as an NDEF URI record.

If you are subscribing for a "WindowsUri" message and your Windows computer receives a message formatted for the proximity technology that your computer supports, Windows reads the formatted message and returns only the Uri as the message content.

WindowsMime

The message data is of a specific mime type. For example, if the message data is a jpeg image, the message type is "WindowsMime.image/jpeg".

Windows will always handle "WindowsMime" messages by prompting the user to view the mime content that was received, even if an app is also subscribed for the mime content.

If you publish a "WindowsMime" message to a computer that is not running Windows, the message content is automatically formatted based on the proximity technology that your computer supports. For example, if your computer uses NFC hardware for proximity, then the message content is formatted as an NDEF Mime record.

If you are publishing a "WindowsMime" message, you must always include the mime type. If you are subscribing to a "WindowsMime" message, you can use "WindowsMime" without specifying the mime type to subscribe for all mime types. If you subscribe to a specific mime type and your Windows computer receives a message formatted for the proximity technology that your computer supports, Windows reads the formatted message and returns only the mime content as the message content. If you subscribe for all mime types, the first 256 bytes received is the ASCII mime type string, and the remaining bytes are the mime content.

Windows:WriteTag

This is the same as the Windows protocol, except that the content is intended to be written to a static tag. The message is not transmitted to any device except a writable static tag. This protocol is only valid for publications. An example of this protocol is "Windows:WriteTag.SampleSubtype".

WindowsUri:WriteTag

This is the same as the WindowsUri protocol, except that the content is intended to be written to a static tag. The message is not transmitted to any device except a writable static tag. This protocol is only valid for publications.

WindowsMime:WriteTag

This is the same as the WindowsMime protocol, except that the content is intended to be written to a static tag. The message is not transmitted to any device except a writable static tag. This protocol is only valid for publications. An example of this protocol is "WindowsMime:WriteTag.image/jpeg".

LaunchApp:WriteTag

Write a tag that can be used to launch a specific app with optional launch parameters. If you publish a LaunchApp:WriteTag message to a tag the result when that tag is tapped to a computer is the same as calling the PeerFinder.Start method and passing your launch parameters. The message must be a UTF-16LE encoded string where the values are delimited by tab characters or null values in the following form:

<launch arguments>[tab]<app platform 1>[tab]<app name 1>...[tab]<app platform N>[tab]<app name N>

You must specify at least one app platform and app name. The app platform for a Windows 8 computer is Windows. The format of the proximity app Id is <package family name>!<app Id>. You can get the package family name from the Windows.ApplicationModel.Package.Current.Id.FamilyName property. You must copy the app Id value from the Id attribute of the Application element in the package manifest for your app. An example of this message is "user=default\tWindows\tExample.Proximity.JS_8wekyb3d8bbwe!Proximity.App".

You can also support other app platforms. For more information, see AlternateIdentities.

WriteableTag

When subscribing for this message protocol, if a writeable tag is brought in to proximity, a proximity message is received that contains an int32 (little endian) indicating the maximum writeable size of the tag. This protocol is only valid for subscriptions.

Pairing:Bluetooth

Windows subscribes to this message type to complete a Bluetooth pairing using proximity. This protocol is not intended to be uses in apps.

NDEF

The message contents are properly formatted NDEF records. The underlying type of the content for a publication using NDEF as the message type is contained in the NDEF records. A subscription for the NDEF type subscribes to all NDEF formatted messages.

NDEF:ext

The message data is application defined NDEF records (TNF field value of 0x04). This protocol only applies to subscriptions, when publishing NDEF content, use NDEF.

NDEF:MIME

The message data is a properly formatted NDEF mime message (TNF field value of 0x02). For example, "NDEF:MIME.image/jpeg". This protocol only applies to subscriptions, when publishing NDEF content, use NDEF.

NDEF:URI

The message data is a properly formatted NDEF message of a type defined by a URI namespace (TNF field value of 0x03).This protocol only applies to subscriptions, when publishing NDEF content, use NDEF. This means that the data format is identified by the specified URI. An example of this protocol is "NDEF:URI.http://contoso.com/sometype".

NDEF:wkt

The message data is a properly formatted NDEF message of a type defined by the NFC forum (TNF field value of 0x01).An example of this type is "NDEF:wkt.U" for the well known type of URI. This protocol only applies to subscriptions, when publishing NDEF content, use NDEF.

NDEF:WriteTag

The message data should be written to an NFC forum standard static tag. The message data must be in a proper NDEF format. This protocol is only valid for publications.

NDEF:Unknown

The message data is an untyped NDEF message (TNF field value of 0x05).This protocol only applies to subscriptions, when publishing NDEF content, use NDEF.

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


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, MessageTransmittedHandler)
Proximity and Tapping (JavaScript)
Proximity and Tapping (C#/VB/C++)
Samples
Proximity sample

 

 

Show:
© 2014 Microsoft