Sdílet prostřednictvím


SmsDevice Class

Definition

Supports the operation of a mobile broadband SMS device.

Note

This functionality is available only 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.

Note

This class and its methods are supported for the maintenance of legacy desktop apps that used it in earlier versions of Windows. If you do use this class, then you must specify the Windows.Devices.Sms.LegacySmsApiContract in your app's manifest. Don't use this class if you're developing a new app for Windows. Instead, use the APIs in this namespace that don't require the Windows.Devices.Sms.LegacySmsApiContract.

public ref class SmsDevice sealed : ISmsDevice
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Devices.Sms.LegacySmsApiContract, 65536)]
/// [Windows.Foundation.Metadata.Deprecated("SmsDevice may be altered or unavailable for releases after Windows 10. Instead, use SmsDevice2.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, Windows.Devices.Sms.LegacySmsApiContract)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class SmsDevice final : ISmsDevice
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Devices.Sms.LegacySmsApiContract, 65536)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Deprecated("SmsDevice may be altered or unavailable for releases after Windows 10. Instead, use SmsDevice2.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, "Windows.Devices.Sms.LegacySmsApiContract")]
class SmsDevice final : ISmsDevice
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Devices.Sms.LegacySmsApiContract), 65536)]
[Windows.Foundation.Metadata.Deprecated("SmsDevice may be altered or unavailable for releases after Windows 10. Instead, use SmsDevice2.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, typeof(Windows.Devices.Sms.LegacySmsApiContract))]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class SmsDevice : ISmsDevice
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Devices.Sms.LegacySmsApiContract), 65536)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Deprecated("SmsDevice may be altered or unavailable for releases after Windows 10. Instead, use SmsDevice2.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, "Windows.Devices.Sms.LegacySmsApiContract")]
public sealed class SmsDevice : ISmsDevice
Public NotInheritable Class SmsDevice
Implements ISmsDevice
Inheritance
Object Platform::Object IInspectable SmsDevice
Attributes
Implements

Windows requirements

Device family
Windows Desktop Extension SDK (introduced in 10.0.10240.0)
API contract
Windows.Devices.Sms.LegacySmsApiContract (introduced in v1.0)
App capabilities
cellularMessaging sms

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

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.

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.

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.

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.

Methods

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.

FromIdAsync(String)

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

FromNetworkAccountIdAsync(String)

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

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.

GetDeviceSelector()

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

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.

Events

SmsDeviceStatusChanged

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

SmsMessageReceived

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

Applies to