使用自定义字符集发送短信
如果需要访问原始消息协议数据单位 (PDU) 来实现文本模式接口不支持的方案,Windows 8、Windows 8.1和Windows 10启用 PDU 模式发送和读取收到的短信。
在以下情况下,可能需要使用 PDU 模式 SMS 接口:
使用 3GPP TS 23.038 中定义的“国家语言单班表”或“国家语言锁定班次表”发送或读取收到的短信。
为每个段使用不同的字符集发送多部分短信。
使用 PDU 模式接口发送短信的 JavaScript 代码示例
function smsDevicePDUSend()
{
if (smsDevice !== null)
{
// Defines a binary message
var smsMessage = new Windows.Devices.Sms.SmsBinaryMessage();
var messsagePdu = “0011000B914152828377F90000AA0CC8F71D14969741F977FD07”;
var messagePduByteArray = hexToByteArray(messsagePdu);
smsMessage.setData(messagePduByteArray);
if (smsDevice.cellularClass === Windows.Devices.Sms.CellularClass.gsm)
{
smsMessage.format = Windows.Devices.Sms.SmsDataFormat.gsmSubmit;
}
else
{
smsMessage.format = Windows.Devices.Sms.SmsDataFormat.cdmaSubmit;
}
var sendSmsMessageOperation = smsDevice.sendMessageAsync(smsMessage);
sendSmsMessageOperation.done(function (reply) {
WinJS.log("Sent message in PDU format", "sample", "status");
}, errorCallback);
}
// Used to convert hex PDU to byte array for sending SMS using PDU //mode
function hexToByteArray(hexString)
{
var result = [];
var hexByte = "";
var decByte = 0;
for (var i = 0; i < hexString.length; i = i + 2) {
hexByte = hexString.substring(i, i + 2);
decByte = parseInt(hexByte, 16);
result.push(decByte);
}
return result;
}
使用 PDU 模式接口读取收到的短信的 JavaScript 代码示例
function smsDeviceRead()
{
try
{
if (smsDevice !== null)
{
var messageStore = smsDevice.messageStore;
var messageID = “1” // select a Message Id to read
// Check for a valid ID number
if (isNaN(messageID) || messageID < 1 || messageID > messageStore.maxMessages)
{
WinJS.log("Invalid ID number", "sample", "error");
return;
}
var getSmsMessageOperation = messageStore.getMessageAsync(messageID);
// Display message when get is completed
getSmsMessageOperation.done(smsMessageReadSuccess, errorCallback);
}
}
catch (err) {
// handle error
}
}
function smsMessageReadSuccess(smsMessage)
{
try
{
if (smsMessage instanceof SmsBinaryMessage) {
var format = smsMessage.format;
var pduData = smsMessage.getData(); // byte array
}
catch (err)
{
WinJS.log("SMS did not set up: " + err, "sample", "error");
}
}