1

我正在開發Windows 8應用程序,用於在JavaScript和Html中使用Toast進行消息傳遞通知。 由於默認烤麪包的聲音是「默認」,但我想將其轉換爲「短信」聲音。 我也在接受用戶的輸入,在通知期間顯示什麼。在應用程序開發中更改Windows 8 Toast通知聲音

我的HTML代碼看起來像

<div>String to display <input type="text" size="20" maxlength="20"  
id="inputString" /></div> 
<button id="inputButton" class="action">button</button> 

JavaScript代碼看起來像

(function() { 
"use strict"; 
var page = WinJS.UI.Pages.define("/html/home.html", { 
    ready: function (element, options) { 
     document.getElementById("inputButton").addEventListener("click", noti, false); 
... 


function noti(e) { 
    var targetButton = e.currentTarget; 

現在我堅持現在做什麼..

我有以下的示例SDK,代碼我無法適應

var toastSoundSource = targetButton.id; 

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

    var content = ToastContent.ToastContentFactory.createToastText02(); 

    content.audio.content = ToastContent.ToastAudioContent[toastSoundSource]; 

我也看過一些博客這說明了可以只是用它

toast.Audio.Content = ToastAudioContent.Silent; 

我想我只是搞亂它來完成。好心幫你soon.thank

回答

0

我是檢查你的代碼,而事實上你的問題是在這裏:

var toastSoundSource = targetButton.id; // you are getting the id of your button, however your button ID is not a valid index for the sounds we have available in Win8. 
content.audio.content = ToastContent.ToastAudioContent[toastSoundSource]; //so when your code arrive here, nothing changes, and Winjs keeps using the DEFAULT sound... 

爲了解決您有問題......你可以做兩件事情,變化按鈕ID爲「短信」或實施的下列方式之一代碼:

月1日 - 強制Windows使用SMS(如果這是你想要使用的唯一的聲音......

function noti(e) { 
    var targetButton = e.currentTarget; 
    var toastSoundSource = targetButton.id; 
    // Get the toast manager for the current app. 
    var notificationManager = Notifications.ToastNotificationManager; 
    var content = ToastContent.ToastContentFactory.createToastText02(); 
    content.audio.content = ToastContent.ToastAudioContent.sms; // force system to use SMS sound 
    var toast = content.createNotification(); 
    notificationManager.createToastNotifier().show(toast); 
} 

第二 - 你可以創建一個if/else語句,如果您有更多可用的選擇,比代碼可以在基於點擊的按鈕聲音選擇...

function noti(e) { 
    var targetButton = e.currentTarget; 
    var toastSoundSource = targetButton.id; 
    // Get the toast manager for the current app. 
    var notificationManager = Notifications.ToastNotificationManager; 
    var content = ToastContent.ToastContentFactory.createToastText02(); 

    if (toastSoundSource == "inputButton") 
     content.audio.content = ToastContent.ToastAudioContent.sms; 
    else 
      content.audio.content = ToastContent.ToastAudioContent.im 

    var toast = content.createNotification(); 
    notificationManager.createToastNotifier().show(toast); 
} 

我希望這有助於:)

相關問題