ProximityDevice.PublishUriMessage 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
PublishUriMessage(Uri) |
将统一资源标识符 (URI) 发布到近似设备。 |
PublishUriMessage(Uri, MessageTransmittedHandler) |
将统一资源标识符 (URI) 发布到近似设备。 传输消息后,将调用指定的处理程序。 |
PublishUriMessage(Uri)
将统一资源标识符 (URI) 发布到近似设备。
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
参数
返回
消息的发布 ID。
- 属性
Windows 要求
应用功能 |
proximity
ID_CAP_PROXIMITY [Windows Phone]
|
示例
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
注解
每个邻近设备一次只能发布一个 URI。
可以通过将 PublishUriMessage 方法返回的发布 ID 传递给 StopPublishingMessage 方法来停止发布 URI。
与邻近设备的其他发布方法不同,URI 发布由 URI 的默认协议处理程序处理。 不需要订阅 URI 消息发布。 可以通过注册 URI 协议(如 HTTP 协议)的默认处理程序来接收 URI 消息。
发送应用程序的 PackageFamilyName 值随 URI 一起自动发送。 如果没有为 URI 的协议注册处理程序,则发送应用程序的 PackageFamilyName 值用于将接收应用程序定向到应用程序存储。
可以使用 PublishMessage 方法将文本消息发布到近似计算机。 可以使用 PublishBinaryMessage 方法发布非文本消息或符合 NDEF 消息标准的消息。
重要
邻近感应 API 不提供身份验证、加密或消息完整性。 不要使用邻近感应来交换用户敏感信息,如密码、财务数据、短信、电子邮件、照片或政府 ID 号。
另请参阅
适用于
PublishUriMessage(Uri, MessageTransmittedHandler)
将统一资源标识符 (URI) 发布到近似设备。 传输消息后,将调用指定的处理程序。
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
参数
- messageTransmittedHandler
- MessageTransmittedHandler
传输消息时要调用的处理程序。
返回
消息的发布 ID。
- 属性
Windows 要求
应用功能 |
proximity
ID_CAP_PROXIMITY [Windows Phone]
|
示例
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
注解
每个邻近设备一次只能发布一个 URI。
可以通过将 PublishUriMessage 方法返回的发布 ID 传递给 StopPublishingMessage 方法来停止发布 URI。
与邻近设备的其他发布方法不同,URI 发布由 URI 的默认协议处理程序处理。 不需要订阅 URI 消息发布。 可以通过注册 URI 协议(如 HTTP 协议)的默认处理程序来接收 URI 消息。
发送应用程序的 PackageFamilyName 值随 URI 一起自动发送。 如果没有为 URI 的协议注册处理程序,则发送应用程序的 PackageFamilyName 值用于将接收应用程序定向到应用程序存储。
可以使用 PublishMessage 方法将文本消息发布到近似计算机。 可以使用 PublishBinaryMessage 方法发布非文本消息或符合 NDEF 消息标准的消息。
重要
邻近感应 API 不提供身份验证、加密或消息完整性。 不要使用邻近感应来交换用户敏感信息,如密码、财务数据、短信、电子邮件、照片或政府 ID 号。