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
參數
傳回
訊息的發行集識別碼。
- 屬性
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 方法傳回的發行集識別碼傳遞至 StopPublishingMessage 方法,以停止發佈 URI。
不同于鄰近裝置的其他發佈方法,URI 發佈是由 URI 的預設通訊協定處理常式處理。 不需要 URI 訊息發行集的訂閱。 您可以註冊 URI 通訊協定的預設處理常式,例如 HTTP 通訊協定來接收 URI 訊息。
傳送應用程式的 PackageFamilyName 值會自動連同 URI 一起傳送。 如果未註冊 URI 通訊協定的處理常式,則傳送應用程式的 PackageFamilyName 值會用來將接收應用程式導向至應用程式存放區。
您可以使用 PublishMessage 方法,將文字訊息發佈至代理電腦。 您可以使用 PublishBinaryMessage 方法來發佈符合 NDEF 傳訊標準的非文字訊息或訊息。
重要
鄰近 API 不提供驗證、加密或訊息完整性。 請勿使用鄰近性來交換使用者敏感性資訊,例如密碼、財務資料、簡訊、電子郵件、相片或政府識別碼。
另請參閱
適用於
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
傳送訊息時要呼叫的處理常式。
傳回
訊息的發行集識別碼。
- 屬性
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 方法傳回的發行集識別碼傳遞至 StopPublishingMessage 方法,以停止發佈 URI。
不同于鄰近裝置的其他發佈方法,URI 發佈是由 URI 的預設通訊協定處理常式處理。 不需要 URI 訊息發行集的訂閱。 您可以註冊 URI 通訊協定的預設處理常式,例如 HTTP 通訊協定來接收 URI 訊息。
傳送應用程式的 PackageFamilyName 值會自動連同 URI 一起傳送。 如果未註冊 URI 通訊協定的處理常式,則傳送應用程式的 PackageFamilyName 值會用來將接收應用程式導向至應用程式存放區。
您可以使用 PublishMessage 方法,將文字訊息發佈至代理電腦。 您可以使用 PublishBinaryMessage 方法來發佈符合 NDEF 傳訊標準的非文字訊息或訊息。
重要
鄰近 API 不提供驗證、加密或訊息完整性。 請勿使用鄰近性來交換使用者敏感性資訊,例如密碼、財務資料、簡訊、電子郵件、相片或政府識別碼。