ProximityDevice.PublishUriMessage Method

Definition

Overloads

PublishUriMessage(Uri)

Publishes a Uniform Resource Identifier (URI) to a proximate device.

PublishUriMessage(Uri, MessageTransmittedHandler)

Publishes a Uniform Resource Identifier (URI) to a proximate device. The specified handler is called when the message has been transmitted.

PublishUriMessage(Uri)

Publishes a Uniform Resource Identifier (URI) to a proximate device.

public:
 virtual long long PublishUriMessage(Uri ^ message) = PublishUriMessage;
/// [Windows.Foundation.Metadata.Overload("PublishUriMessage")]
long PublishUriMessage(Uri const& message);
[Windows.Foundation.Metadata.Overload("PublishUriMessage")]
public long PublishUriMessage(System.Uri message);
function publishUriMessage(message)
Public Function PublishUriMessage (message As Uri) As Long

Parameters

message
Uri Uri

The URI to publish.

Returns

Int64

long long

long

The publication ID of the message.

Attributes

Windows requirements

App capabilities
proximity ID_CAP_PROXIMITY [Windows Phone]

Examples

private Windows.Networking.Proximity.ProximityDevice proximityDevice;
    
public MainPage()
{
    this.InitializeComponent();

    initializeProximitySample();
}

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

    if (proximityDevice == null)
        WriteMessageText("Failed to initialized proximity device.\n" +
                         "Your device may not have proximity hardware.");
}

// 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;
        });
}
Private proximityDevice As Windows.Networking.Proximity.ProximityDevice

Public Sub New()
    Me.InitializeComponent()

    initializeProximitySample()
End Sub

Private Sub initializeProximitySample()
    proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault()

    If proximityDevice Is Nothing Then
        WriteMessageText("Failed to initialized proximity device." & vbCrLf &
                         "Your device may not have proximity hardware.")
    End If
End Sub

' Write a message to MessageBlock on the UI thread.
Private Async Sub WriteMessageText(message As String, Optional overwrite As Boolean = False)
    Await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
            Sub()
                If overwrite Then
                    MessageBlock.Text = message
                Else
                    MessageBlock.Text &= message
                End If
            End Sub)
End Sub
long publishedUriId = -1;

private void PublishUriButton_Click(object sender, RoutedEventArgs e)
{
    // Stop publishing the current message.
    if (publishedUriId != -1)
        proximityDevice.StopPublishingMessage(publishedUriId);

    publishedUriId =
        proximityDevice.PublishUriMessage(new Uri("http://www.microsoft.com"));
}

private void StopPublishingUriButton_Click(object sender, RoutedEventArgs e)
{
    proximityDevice.StopPublishingMessage(publishedUriId);
}
Private publishedUriId As Long = -1

Private Sub PublishUriButton_Click(sender As Object, e As RoutedEventArgs)
    ' Stop publishing the current message.
    If publishedUriId <> -1 Then
        proximityDevice.StopPublishingMessage(publishedUriId)
    End If

    publishedUriId =
        proximityDevice.PublishUriMessage(New Uri("http:'www.microsoft.com"))
End Sub

Private Sub StopPublishingUriButton_Click()
    proximityDevice.StopPublishingMessage(publishedUriId)
End Sub

Remarks

Only one URI can be published at a time for each proximity device.

You can stop publishing a URI by passing the publication ID returned by the PublishUriMessage method to the StopPublishingMessage method.

Unlike the other publish methods for a proximity device, URI publishing is handled by the default protocol handler for the URI. A subscription to a URI message publication is not required. You can receive URI messages by registering a default handler for a URI protocol such as the HTTP protocol.

The PackageFamilyName value of the sending application is automatically sent along with the URI. If no handler is registered for the protocol of a URI, the PackageFamilyName value of the sending application is used to direct the receiving application to the application store.

You can use the PublishMessage method to publish a text message to a proximate computer. You can use the PublishBinaryMessage method to publish non-text messages or messages that conform to the NDEF messaging standard.

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.

See also

Applies to

PublishUriMessage(Uri, MessageTransmittedHandler)

Publishes a Uniform Resource Identifier (URI) to a proximate device. The specified handler is called when the message has been transmitted.

public:
 virtual long long PublishUriMessage(Uri ^ message, MessageTransmittedHandler ^ messageTransmittedHandler) = PublishUriMessage;
/// [Windows.Foundation.Metadata.Overload("PublishUriMessageWithCallback")]
long PublishUriMessage(Uri const& message, MessageTransmittedHandler const& messageTransmittedHandler);
[Windows.Foundation.Metadata.Overload("PublishUriMessageWithCallback")]
public long PublishUriMessage(System.Uri message, MessageTransmittedHandler messageTransmittedHandler);
function publishUriMessage(message, messageTransmittedHandler)
Public Function PublishUriMessage (message As Uri, messageTransmittedHandler As MessageTransmittedHandler) As Long

Parameters

message
Uri Uri

The URI to publish.

messageTransmittedHandler
MessageTransmittedHandler

The handler to call when the message has been transmitted.

Returns

Int64

long long

long

The publication ID of the message.

Attributes

Windows requirements

App capabilities
proximity ID_CAP_PROXIMITY [Windows Phone]

Examples

private Windows.Networking.Proximity.ProximityDevice proximityDevice;
    
public MainPage()
{
    this.InitializeComponent();

    initializeProximitySample();
}

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

    if (proximityDevice == null)
        WriteMessageText("Failed to initialized proximity device.\n" +
                         "Your device may not have proximity hardware.");
}

// 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;
        });
}
Private proximityDevice As Windows.Networking.Proximity.ProximityDevice

Public Sub New()
    Me.InitializeComponent()

    initializeProximitySample()
End Sub

Private Sub initializeProximitySample()
    proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault()

    If proximityDevice Is Nothing Then
        WriteMessageText("Failed to initialized proximity device." & vbCrLf &
                         "Your device may not have proximity hardware.")
    End If
End Sub

' Write a message to MessageBlock on the UI thread.
Private Async Sub WriteMessageText(message As String, Optional overwrite As Boolean = False)
    Await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
            Sub()
                If overwrite Then
                    MessageBlock.Text = message
                Else
                    MessageBlock.Text &= message
                End If
            End Sub)
End Sub
    long publishedUriId = -1;

    private void PublishUriButton_Click(object sender, RoutedEventArgs e)
    {
        // Stop publishing the current message.
        if (publishedUriId != -1)
            proximityDevice.StopPublishingMessage(publishedUriId);

        publishedUriId =
            proximityDevice.PublishUriMessage(new Uri("http://www.microsoft.com"),
                                              UriTransmitted);
    }

private void UriTransmitted(
    Windows.Networking.Proximity.ProximityDevice sender,
        long messageId)
    {
    // The Uri has been successfully transmitted.
    }

    private void StopPublishingUriButton_Click(object sender, RoutedEventArgs e)
    {
        proximityDevice.StopPublishingMessage(publishedUriId);
    }
Private publishedUriId As Long = -1

Private Sub PublishUriButton_Click(sender As Object, e As RoutedEventArgs)
    ' Stop publishing the current message.
    If publishedUriId <> -1 Then
        proximityDevice.StopPublishingMessage(publishedUriId)
    End If

    publishedUriId =
        proximityDevice.PublishUriMessage(New Uri("http:'www.microsoft.com"),
                                          AddressOf UriTransmitted)
End Sub

Private Sub UriTransmitted(
sender As Windows.Networking.Proximity.ProximityDevice,
    messageId As Long)

' The Uri has been successfully transmitted
End Sub

Private Sub StopPublishingUriButton_Click()
    proximityDevice.StopPublishingMessage(publishedUriId)
End Sub

Remarks

Only one URI can be published at a time for each proximity device.

You can stop publishing a URI by passing the publication ID returned by the PublishUriMessage method to the StopPublishingMessage method.

Unlike the other publish methods for a proximity device, URI publishing is handled by the default protocol handler for the URI. A subscription to a URI message publication is not required. You can receive URI messages by registering a default handler for a URI protocol such as the HTTP protocol.

The PackageFamilyName value of the sending application is automatically sent along with the URI. If no handler is registered for the protocol of a URI, the PackageFamilyName value of the sending application is used to direct the receiving application to the application store.

You can use the PublishMessage method to publish a text message to a proximate computer. You can use the PublishBinaryMessage method to publish non-text messages or messages that conform to the NDEF messaging standard.

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.

See also

Applies to