0

以下代码适用于 CLICK 事件处理程序,但我不能让它自动发送

 async void Button_Click_1(object sender, RoutedEventArgs e)
    {
        SmsDevice smsDevice2 = (SmsDevice)await SmsDevice.GetDefaultAsync();

        // Create a text message - Set destination number and message text
        SmsTextMessage msg = new SmsTextMessage();
        msg.To = "12345678";
        msg.Body = "xxxx";

        // Send the message asynchronously
        await smsDevice2.SendMessageAsync(msg);


    }

这不起作用(后台服务)

  async void DisplayToastAsync(IBackgroundTaskInstance taskInstance, ManualResetEvent manualEventWaiter)
    {
        SmsDevice smsDevice2 = (SmsDevice)await SmsDevice.GetDefaultAsync();
        // Create a text message - Set destination number and message text
        SmsTextMessage msg = new SmsTextMessage();
        msg.To = "12345678";
        msg.Body = "xxx";

        // Send the message asynchronously
        await smsDevice2.SendMessageAsync(msg);

}

有谁知道为什么?我该如何解决?

4

1 回答 1

1

我正在试验,我发现您确实需要填写“发件人”字段(的副本SmsDevice.AccountPhoneNumber)。

话虽如此,我仍然得到所谓的“通用错误”,但至少它不是“参数错误”。

如果您有兴趣,我的一般错误是 0x80548212。

另外——我猜你已经这样做了(或者我认为你会得到一个空的短信设备)——但你需要让应用程序能够在清单中发送短信。

更多信息 - 通用错误是我的 SIM 卡仅启用了数据。换成包含 SMS 的 SIM 卡后,代码运行良好。

于 2012-05-24T15:07:45.247 回答