Windows Phone 8.1中的警报线。但是它无法响铃。当我设置它设置的闹钟

时间:2015-05-19 08:30:45

标签: windows-phone-8 windows-phone windows-phone-8.1

Windows Phone 8.1中的警报线。但是它无法响铃。当我在它上面设置闹钟时。对接没有响。没有任何Eroor

public Alarm()
{
    this.InitializeComponent();
    this.NavigationCacheMode = NavigationCacheMode.Required;
}

/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}

private async void Button_Click(object sender, RoutedEventArgs e)
{
     try
    {
        int snooze;
        string audioSrc;
        int year = datepicker.Date.Year;
        int month = datepicker.Date.Month;
        int day = datepicker.Date.Day;
        int hour = timepicker.Time.Hours;
        int min = timepicker.Time.Minutes;
        int sec = timepicker.Time.Seconds;
        //string audioSrc = alrm_sound.SelectionBoxItem.ToString();
        try
        {
            snooze = Convert.ToInt16(CustomSnoozeTime.SelectionBoxItem.ToString());
        }
        catch
        {
            snooze = 5;
        }
        try
        {
            audioSrc = alrm_sound.SelectionBoxItem.ToString();
        }
        catch
        {
            audioSrc = "Default";
        }
        DateTime myDate1 = new DateTime(year, month, day, hour, min, sec);

        DateTime myDate2 = DateTime.Now;
        TimeSpan myDateResult = new TimeSpan();
        myDateResult = myDate1 - myDate2;
        if (myDate2 > myDate1)
        {
            var x = new MessageDialog("Invalid date or time");
            await x.ShowAsync();
        }
        else
        {

            string title = "Alarm!";
            string message = alm_msg.Text;
            string imgURL = "ms-appx:///Assets/Capture.PNG";

            string toastXmlString =
             "<toast><visual version='1'><binding template='toastImageAndText02'><text id='1'>"
           + title + "</text><text id='2'>"
                + message + "</text><image id='1' src='" + imgURL + "'/></binding></visual>\n" +
                 "<commands scenario=\"alarm\">\n" +
                    "<command id=\"snooze\"/>\n" +
                    "<command id=\"dismiss\"/>\n" +
                "</commands>\n" +
                      "<audio src='ms-winsoundevent:Notification." + audioSrc + "'/>" +
                "</toast>";

            Windows.Data.Xml.Dom.XmlDocument toastDOM = new Windows.Data.Xml.Dom.XmlDocument();
            toastDOM.LoadXml(toastXmlString);
            var toastNotifier1 = Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier();

            double x1 = myDateResult.TotalSeconds;
            int customSnoozeSeconds = snooze * 60;

            TimeSpan snoozeInterval = TimeSpan.FromSeconds(customSnoozeSeconds);

            var customAlarmScheduledToast = new Windows.UI.Notifications.ScheduledToastNotification(toastDOM, DateTime.Now.AddSeconds(x1), snoozeInterval, 0);

            toastNotifier1.AddToSchedule(customAlarmScheduledToast);
            var x = new MessageDialog("Alarm Set!");
            await x.ShowAsync();
        }

    }
    catch
    { }
}

Windows Phone 8.1中的警报线。但是它无法响铃。当我在它上面设置闹钟时。屁股不响了

0 个答案:

没有答案
相关问题