1

トースト通知引数を送信して、Webブラウザーを開く必要があります。これが私のコードです:

private void DoNotification()
    {
        var notifications = serviceClient.GetNotificationsAsync(App.CurrentRestaurantLocation.ID);
        foreach (RestaurantNotification note in notifications.Result)
        {
            IToastNotificationContent toastContent = null;
            IToastText02 templateContent = ToastContentFactory.CreateToastText02();
            templateContent.TextHeading.Text = note.Title;
            templateContent.TextBodyWrap.Text = note.Message;
            toastContent = templateContent;
            // Create a toast, then create a ToastNotifier object to show
            // the toast
            ToastNotification toast = toastContent.CreateNotification();

            toast.Activated += toast_Activated;
            // If you have other applications in your package, you can specify the AppId of
            // the app to create a ToastNotifier for that application
            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
    }

    async void toast_Activated(ToastNotification sender, object args)
    {
        await Launcher.LaunchUriAsync(new Uri("http://www.google.com"));
    }

アクティブ化されたイベントが発生しましたが、Webブラウザが開きません。そのランチャーコードは、トースト通知なしで機能します。

argsにURLを入力するにはどうすればよいですか?私のWebサービスはnote.RedirectUrlを返し、そこにフィードしたいと思います。

4

1 に答える 1

0

Activatedでイベントハンドラーを使用する代わりに、メインのApplicationクラスでハンドラーをToastNotification使用しOnLaunchedます(これにより、起動コンテキストに簡単にアクセスできます)。

ハンドラーを呼び出すには、トーストXMLで起動引数を指定する必要があります。上記のコードを使用して、次のIToastContentようにオブジェクトに引数を追加できます。

toastContent.Launch = note.RedirectUrl;

次に、アプリケーションのOnLaunchedメソッドで、アプリは起動引数を取得できます。

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
    if (!String.IsNullOrEmpty(args.Argument)) {
        var redirectUrl = args.Argument;
    }
}

から使用すると、呼び出しLaunchUriAsyncは期待どおりに機能するはずOnLaunchedです。

于 2012-09-24T20:26:12.227 に答える