ProximityMessage class
Represents a message that's received from a subscription.
Syntax
public sealed class ProximityMessage : Object
Attributes
- DualApiPartitionAttribute()
- MarshalingBehaviorAttribute(Agile)
- VersionAttribute(NTDDI_WIN8)
Members
The ProximityMessage class has these types of members:
Methods
The ProximityMessage class inherits methods from the Object class (C#/VB/C++).
Properties
The ProximityMessage class has these properties.
| Property | Access type | Description |
|---|---|---|
| Read-only | Gets the binary data of the message. | |
| Read-only | Gets the message data as text. | |
| Read-only | Gets the type of the message. | |
| Read-only | Gets the subscription ID of the message. |
Examples
Windows.Networking.Proximity.ProximityDevice proximityDevice; long publishedMessageId = -1; long subscribedMessageId = -1; private void initializeProximityDevice() { proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault(); if (proximityDevice != null) { PublishMessageButton.Click += PublishMessage; SubscribeForMessageButton.Click += SubscribeForMessage; StopSubscribingForMessageButton.Click += StopSubscribingForMessage; StopPublishingMessageButton.Click += StopPublishingMessage; } else { WriteMessageText("Failed to initialized proximity device.\n"); } } private void PublishMessage(object sender, RoutedEventArgs e) { // Stop publishing the current message. if (publishedMessageId != -1) { proximityDevice.StopPublishingMessage(publishedMessageId); } publishedMessageId = proximityDevice.PublishMessage("Windows.SampleMessage", MessageTextBlock.Text); } private void SubscribeForMessage(object sender, RoutedEventArgs e) { // Only subscribe for the message one time. if (subscribedMessageId == -1) { subscribedMessageId = proximityDevice.SubscribeForMessage("Windows.SampleMessage", messageReceived); } } private void messageReceived( Windows.Networking.Proximity.ProximityDevice device, Windows.Networking.Proximity.ProximityMessage message) { MessageBlock.Text += "Message received: " + message.DataAsString + "\n"; } private void StopSubscribingForMessage(object sender, RoutedEventArgs e) { proximityDevice.StopSubscribingForMessage(subscribedMessageId); subscribedMessageId = -1; } private void StopPublishingMessage(object sender, RoutedEventArgs e) { proximityDevice.StopPublishingMessage(publishedMessageId); publishedMessageId = -1; } // Write a message to MessageBlock on the UI thread. private Windows.UI.Core.CoreDispatcher messageDispatcher = Window.Current.CoreWindow.Dispatcher; async private void WriteMessageText(string message, bool overwrite = false) { await messageDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { if (overwrite) MessageBlock.Text = message; else MessageBlock.Text += message; }); }
Requirements
|
Minimum supported client | Windows 8 [Windows Store apps, desktop apps] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps, desktop apps] |
|
Minimum supported phone | Windows Phone 8 |
|
Namespace |
|
|
Metadata |
|
|
Capabilities |
|
See also
Build date: 2/25/2013
