SmsDevice SmsDevice SmsDevice SmsDevice Class

Definition

Supports the operation of a mobile broadband SMS device.

Note

This functionality is only available to mobile operator apps and UWP apps given privileged access by mobile network operators, mobile broadband adapter IHV, or OEM. For more information, see Mobile Broadband: device apps.

Note

Note that this class and its methods are supported for the maintenance of legacy desktop apps that used it in earlier versions of Windows; and if you do use this class, you must specify the Windows.Devices.Sms.LegacySmsApiContract in your app's manifest. Do not use this class if you are developing new apps for Windows 10. Instead, use the members of this namespace that do not require the Windows.Devices.Sms.LegacySmsApiContract.

public : sealed class SmsDevice : ISmsDevice
public sealed class SmsDevice : ISmsDevice
Public NotInheritable Class SmsDevice Implements ISmsDevice
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows Desktop Extension SDK (introduced v10.0.10240.0)
API contract
Windows.Devices.Sms.LegacySmsApiContract (introduced v1)
Capabilities
sms cellularMessaging

Remarks

Apps that use the Windows.Devices.Sms API to send or receive text messages fail with E_ACCESS_DENIED if the user revokes access.

If access to the SMS device has been given to an app:

  • Calling GetDefaultAsync or FromIdAsync triggers a consent prompt the first time the app is run.
  • The error handlers for the asynchronous methods of GetDefaultAsync and FromIdAsync receive E_ACCESS_DENIED if the user did not grant permission in the consent prompt or if permission is revoked.
  • If the user re-enables access to SMS after revoking it, call GetDefaultAsync or FromIdAsync again to access SMS. For example, the error handler for E_ACCESS_DENIED error could display UI to instruct the user to re-enable SMS using the settings charm and to then tap a button to retry accessing SMS. The code behind the button should call GetDefaultAsync or FromIdAsync before making any other calls.
  • If the app is registering for the SMS background event (Windows.ApplicationModel.Background.SystemTriggerType.SmsReceived ), the app has to first call GetDefaultAsync or FromIdAsync again to access SMS to ensure the app has access. Calling GetDefaultAsync or FromIdAsync from the background task will not trigger a consent prompt. If it is a first time run or if the user did not grant permission or if permission is revoked then it will receive an E_ACCESS_DENIED.

The first use of the SmsDevice object to call FromIdAsync or GetDefaultAsync by applications written in C# or C++ should be on the single-threaded apartment (STA) thread. Calls from a multi-threaded apartment (MTA) thread may result in undefined behavior.

Properties

AccountPhoneNumber AccountPhoneNumber AccountPhoneNumber AccountPhoneNumber

Returns the phone number associated with the SMS device. The phone number can be used to associate incoming messages with the account and possibly an external storage mechanism such as an account inbox.

public : Platform::String AccountPhoneNumber { get; }
public string AccountPhoneNumber { get; }
Public ReadOnly Property AccountPhoneNumber As string
var string = smsDevice.accountPhoneNumber;
Value
Platform::String string string string

A string representation of the account phone number.

Additional features and requirements
Device family
Windows Desktop Extension SDK (introduced v10.0.10240.0)
API contract
Windows.Devices.Sms.LegacySmsApiContract (introduced v1)
Capabilities
sms cellularMessaging

CellularClass CellularClass CellularClass CellularClass

Returns the cellular class of the SMS device. The class can be used to determine which encodings are appropriate or which device limitations are in effect.

public : CellularClass CellularClass { get; }
public CellularClass CellularClass { get; }
Public ReadOnly Property CellularClass As CellularClass
var cellularClass = smsDevice.cellularClass;
Value
CellularClass CellularClass CellularClass CellularClass

An enumerated value indicating the device's cellular class.

Additional features and requirements
Device family
Windows Desktop Extension SDK (introduced v10.0.10240.0)
API contract
Windows.Devices.Sms.LegacySmsApiContract (introduced v1)
Capabilities
sms cellularMessaging

DeviceStatus DeviceStatus DeviceStatus DeviceStatus

Returns the SMS device's status, which indicates whether the device is ready, or not. It also indicates what type of problem exists if the device is not ready.

public : SmsDeviceStatus DeviceStatus { get; }
public SmsDeviceStatus DeviceStatus { get; }
Public ReadOnly Property DeviceStatus As SmsDeviceStatus
var smsDeviceStatus = smsDevice.deviceStatus;
Value
SmsDeviceStatus SmsDeviceStatus SmsDeviceStatus SmsDeviceStatus

An enumerated value that indicates the readiness of an SMS device to engage in cellular network traffic operations.

Additional features and requirements
Device family
Windows Desktop Extension SDK (introduced v10.0.10240.0)
API contract
Windows.Devices.Sms.LegacySmsApiContract (introduced v1)
Capabilities
sms cellularMessaging

MessageStore MessageStore MessageStore MessageStore

Accesses the on-device message store. The store holds messages until a client can retrieve them. On some devices, for example, the store may correspond to the SIM storage for SMS messages.

public : SmsDeviceMessageStore MessageStore { get; }
public SmsDeviceMessageStore MessageStore { get; }
Public ReadOnly Property MessageStore As SmsDeviceMessageStore
var smsDeviceMessageStore = smsDevice.messageStore;
Additional features and requirements
Device family
Windows Desktop Extension SDK (introduced v10.0.10240.0)
API contract
Windows.Devices.Sms.LegacySmsApiContract (introduced v1)
Capabilities
sms cellularMessaging

Methods

CalculateLength(SmsTextMessage) CalculateLength(SmsTextMessage) CalculateLength(SmsTextMessage) CalculateLength(SmsTextMessage)

Estimates the transmitted message length of the specified text message. The estimate can be useful to clients who want to give an indication of how many messages will be sent on the network to carry the text of the full message.

public : SmsEncodedLength CalculateLength(SmsTextMessage message)
public SmsEncodedLength CalculateLength(SmsTextMessage message)
Public Function CalculateLength(message As SmsTextMessage) As SmsEncodedLength
var smsEncodedLength = smsDevice.calculateLength(message);
Parameters
message
SmsTextMessage SmsTextMessage SmsTextMessage SmsTextMessage

A reference to the SMS text message to measure.

Returns

A reference to an SmsEncodedLength structure that is populated with the length information.

Additional features and requirements
Device family
Windows Desktop Extension SDK (introduced v10.0.10240.0)
API contract
Windows.Devices.Sms.LegacySmsApiContract (introduced v1)
Capabilities
sms cellularMessaging

FromIdAsync(String) FromIdAsync(String) FromIdAsync(String) FromIdAsync(String)

Creates an instance of SmsDevice for the device that received the SMS message.

public : static IAsyncOperation<SmsDevice> FromIdAsync(Platform::String deviceId)
public static IAsyncOperation<SmsDevice> FromIdAsync(String deviceId)
Public Static Function FromIdAsync(deviceId As String) As IAsyncOperation( Of SmsDevice )
Windows.Devices.Sms.SmsDevice.fromIdAsync(deviceId).done( /* Your success and error handlers */ );
Parameters
deviceId
Platform::String String String String

A string representation of the DeviceInformation ID of the SMS device that received the SMS message.

Returns
Additional features and requirements
Device family
Windows Desktop Extension SDK (introduced v10.0.10240.0)
API contract
Windows.Devices.Sms.LegacySmsApiContract (introduced v1)
Capabilities
sms cellularMessaging

Remarks

The SmsReceivedEventDetails interface handles the details of a received message; you can pass the DeviceInformation ID from that interface to this method to activate the device and retrieve additional message details, such as the sender and the body of the message. Because the device might be busy, the operation executes asynchronously. The asynchronous operation object returns immediately.

FromNetworkAccountIdAsync(String) FromNetworkAccountIdAsync(String) FromNetworkAccountIdAsync(String) FromNetworkAccountIdAsync(String)

Creates an instance of SmsDevice for the specified Mobile Broadband network account ID.

public : static IAsyncOperation<SmsDevice> FromNetworkAccountIdAsync(Platform::String networkAccountId)
public static IAsyncOperation<SmsDevice> FromNetworkAccountIdAsync(String networkAccountId)
Public Static Function FromNetworkAccountIdAsync(networkAccountId As String) As IAsyncOperation( Of SmsDevice )
Windows.Devices.Sms.SmsDevice.fromNetworkAccountIdAsync(networkAccountId).done( /* Your success and error handlers */ );
Parameters
networkAccountId
Platform::String String String String

The Mobile Broadband network account ID to use to select the corresponding mobile broadband device to use for the SMS device

Returns

When this method completes, it returns the SmsDevice for the specified Mobile Broadband network account ID.

Additional features and requirements
Device family
Windows Desktop Extension SDK (introduced v10.0.10240.0)
API contract
Windows.Devices.Sms.LegacySmsApiContract (introduced v1)
Capabilities
sms cellularMessaging

GetDefaultAsync() GetDefaultAsync() GetDefaultAsync() GetDefaultAsync()

Creates an instance of an SmsDevice object associated with the default SMS device. Because the device might be busy, the operation executes asynchronously. The asynchronous operation object returns immediately.

public : static IAsyncOperation<SmsDevice> GetDefaultAsync()
public static IAsyncOperation<SmsDevice> GetDefaultAsync()
Public Static Function GetDefaultAsync() As IAsyncOperation( Of SmsDevice )
Windows.Devices.Sms.SmsDevice.getDefaultAsync().done( /* Your success and error handlers */ );
Returns
Additional features and requirements
Device family
Windows Desktop Extension SDK (introduced v10.0.10240.0)
API contract
Windows.Devices.Sms.LegacySmsApiContract (introduced v1)
Capabilities
sms cellularMessaging

GetDeviceSelector() GetDeviceSelector() GetDeviceSelector() GetDeviceSelector()

Retrieves the class selection string that can be used to enumerate SMS devices.

public : static Platform::String GetDeviceSelector()
public static string GetDeviceSelector()
Public Static Function GetDeviceSelector() As string
var string = Windows.Devices.Sms.SmsDevice.getDeviceSelector();
Returns
Platform::String string string string

A reference to an Advanced Query Syntax (AQS) string that identifies an SMS device.

Additional features and requirements
Device family
Windows Desktop Extension SDK (introduced v10.0.10240.0)
API contract
Windows.Devices.Sms.LegacySmsApiContract (introduced v1)
Capabilities
sms cellularMessaging

SendMessageAsync(ISmsMessage) SendMessageAsync(ISmsMessage) SendMessageAsync(ISmsMessage) SendMessageAsync(ISmsMessage)

Asynchronously sends a message using the SMS device. The method is asynchronous because the send operation might not occur instantaneously. The message operation object is returned immediately.

public : SendSmsMessageOperation SendMessageAsync(ISmsMessage message)
public SendSmsMessageOperation SendMessageAsync(ISmsMessage message)
Public Function SendMessageAsync(message As ISmsMessage) As SendSmsMessageOperation
Windows.Devices.Sms.SmsDevice.sendMessageAsync(message).done( /* Your success and error handlers */ );
Parameters
message
ISmsMessage ISmsMessage ISmsMessage ISmsMessage

A reference to an ISmsMessage object. The message can be in text or binary format.

Returns
Additional features and requirements
Device family
Windows Desktop Extension SDK (introduced v10.0.10240.0)
API contract
Windows.Devices.Sms.LegacySmsApiContract (introduced v1)
Capabilities
sms cellularMessaging

Events

SmsDeviceStatusChanged SmsDeviceStatusChanged SmsDeviceStatusChanged SmsDeviceStatusChanged

Sets an event handler to be called when the status of the SMS device changes.

public : event SmsDeviceStatusChangedEventHandler SmsDeviceStatusChanged<>
public event SmsDeviceStatusChangedEventHandler SmsDeviceStatusChanged<>
Public Event SmsDeviceStatusChangedEventHandler SmsDeviceStatusChanged( Of )
function onSmsDeviceStatusChanged(eventArgs){/* Your code */}


smsDevice.addEventListener("smsDeviceStatusChanged", onSmsDeviceStatusChanged);
smsDevice.removeEventListener("smsDeviceStatusChanged", onSmsDeviceStatusChanged);
Additional features and requirements
Device family
Windows Desktop Extension SDK (introduced v10.0.10240.0)
API contract
Windows.Devices.Sms.LegacySmsApiContract (introduced v1)
Capabilities
sms cellularMessaging

SmsMessageReceived SmsMessageReceived SmsMessageReceived SmsMessageReceived

Sets an event handler to be called when the device receives a new text message.

public : event SmsMessageReceivedEventHandler SmsMessageReceived<>
public event SmsMessageReceivedEventHandler SmsMessageReceived<>
Public Event SmsMessageReceivedEventHandler SmsMessageReceived( Of )
function onSmsMessageReceived(eventArgs){/* Your code */}


smsDevice.addEventListener("smsMessageReceived", onSmsMessageReceived);
smsDevice.removeEventListener("smsMessageReceived", onSmsMessageReceived);
Additional features and requirements
Device family
Windows Desktop Extension SDK (introduced v10.0.10240.0)
API contract
Windows.Devices.Sms.LegacySmsApiContract (introduced v1)
Capabilities
sms cellularMessaging