ToastNotificationManager.CreateToastNotifier 方法

定義

多載

CreateToastNotifier()

建立並初始化 ToastNotification的新實例,此實例系結至呼叫的應用程式,可讓您向該應用程式發出快顯通知。

CreateToastNotifier(String)

建立並初始化 ToastNotification的新實例,系結至指定的應用程式,通常是相同套件中的另一個應用程式。

CreateToastNotifier()

建立並初始化 ToastNotification的新實例,此實例系結至呼叫的應用程式,可讓您向該應用程式發出快顯通知。

public:
 static ToastNotifier ^ CreateToastNotifier();
/// [Windows.Foundation.Metadata.Overload("CreateToastNotifier")]
 static ToastNotifier CreateToastNotifier();
[Windows.Foundation.Metadata.Overload("CreateToastNotifier")]
public static ToastNotifier CreateToastNotifier();
function createToastNotifier()
Public Shared Function CreateToastNotifier () As ToastNotifier

傳回

您將用來將快顯通知傳送至應用程式的物件。

屬性

範例

下列範例示範如何建立並傳送包含文字和影像的快顯通知,包括使用 CreateToastNotifier 方法。

var notifications = Windows.UI.Notifications;

// Get the toast notification manager for the current app.
var notificationManager = notifications.ToastNotificationManager;

// The getTemplateContent method returns a Windows.Data.Xml.Dom.XmlDocument object
// that contains the toast notification XML content.
var template = notifications.toastTemplateType.toastImageAndText01;
var toastXml = notificationManager.getTemplateContent(notifications.ToastTemplateType[template]);

// You can use the methods from the XML document to specify the required elements for the toast.
var images = toastXml.getElementsByTagName("image");
images[0].setAttribute("src", "images/toastImageAndText.png");

var textNodes = toastXml.getElementsByTagName("text");
textNodes.forEach(function (value, index) {
    var textNumber = index + 1;
    var text = "";
    for (var j = 0; j < 10; j++) {
        text += "Text input " + /*@static_cast(String)*/textNumber + " ";
    }
    value.appendChild(toastXml.createTextNode(text));
});

// Create a toast notification from the XML, then create a ToastNotifier object
// to send the toast.
var toast = new notifications.ToastNotification(toastXml);

notificationManager.createToastNotifier().show(toast);

備註

建立傳統型應用程式的快顯通知器時,請勿使用此多載。 使用 CreateToastNotifier (appID) 來提供所需的 AppUserModelID

如果您的 app 使用背景語音網際網路通訊協定 (VOIP) 代理程式,則必須指定應用程式識別碼以顯示快顯通知。 使用 CreateToastNotifier (appID) 方法多載。

另請參閱

適用於

CreateToastNotifier(String)

建立並初始化 ToastNotification的新實例,系結至指定的應用程式,通常是相同套件中的另一個應用程式。

public:
 static ToastNotifier ^ CreateToastNotifier(Platform::String ^ applicationId);
/// [Windows.Foundation.Metadata.Overload("CreateToastNotifierWithId")]
 static ToastNotifier CreateToastNotifier(winrt::hstring const& applicationId);
[Windows.Foundation.Metadata.Overload("CreateToastNotifierWithId")]
public static ToastNotifier CreateToastNotifier(string applicationId);
function createToastNotifier(applicationId)
Public Shared Function CreateToastNotifier (applicationId As String) As ToastNotifier

參數

applicationId
String

Platform::String

winrt::hstring

應用程式的唯一識別碼。

注意

您無法將快顯通知傳送至次要磚,因此這必須是應用程式磚的識別碼。

傳回

您將用來將快顯通知傳送至磚的物件。

屬性

備註

由 applicationId識別的應用程式必須屬於與呼叫端相同的套件。

如果您的 app 使用背景語音透過網際網路通訊協定 (VOIP) 代理程式,指定在該案例中顯示快顯通知所需的應用程式識別碼,請使用這個形式的 方法。

從傳統型應用程式傳送快顯通知

一般而言,從傳統型應用程式傳送快顯通知與從 UWP 應用程式傳送通知相同。 不過,您應該注意這些差異和需求:

  • 若要讓傳統型應用程式顯示快顯通知,應用程式必須在 [開始] 畫面上具有快捷方式。
  • 快捷方式必須具有 AppUserModelID
  • 傳統型應用程式無法排程快顯通知。

如需詳細資訊,請參閱下列主題:

另請參閱

適用於