Skip to content

Most visited

Recently visited

navigation

SubscriptionManager

public class SubscriptionManager
extends Object

java.lang.Object
   ↳ android.telephony.SubscriptionManager


SubscriptionManager is the application interface to SubscriptionController and provides information about the current Telephony Subscriptions.

All SDK public methods require android.Manifest.permission.READ_PHONE_STATE.

Instances of this class must be obtained using Context.getSystemService(Class) with the argument SubscriptionManager.class or Context.getSystemService(String) with the argument Context.TELEPHONY_SUBSCRIPTION_SERVICE.

Summary

Nested classes

class SubscriptionManager.OnSubscriptionsChangedListener

A listener class for monitoring changes to SubscriptionInfo records. 

Constants

String ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED

Broadcast Action: The default sms subscription has changed.

String ACTION_DEFAULT_SUBSCRIPTION_CHANGED

Broadcast Action: The default subscription has changed.

int DATA_ROAMING_DISABLE

Indicates that data roaming is disabled for a subscription

int DATA_ROAMING_ENABLE

Indicates that data roaming is enabled for a subscription

String EXTRA_SUBSCRIPTION_INDEX

Integer extra used with ACTION_DEFAULT_SUBSCRIPTION_CHANGED and ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED to indicate the subscription which has changed.

int INVALID_SUBSCRIPTION_ID

An invalid subscription identifier

Public methods

void addOnSubscriptionsChangedListener(SubscriptionManager.OnSubscriptionsChangedListener listener)

Register for changes to the list of active SubscriptionInfo records or to the individual records themselves.

static SubscriptionManager from(Context context)

Get an instance of the SubscriptionManager from the Context.

SubscriptionInfo getActiveSubscriptionInfo(int subId)

Get the active SubscriptionInfo with the input subId.

int getActiveSubscriptionInfoCount()
int getActiveSubscriptionInfoCountMax()
SubscriptionInfo getActiveSubscriptionInfoForSimSlotIndex(int slotIndex)

Get the active SubscriptionInfo associated with the slotIndex

List<SubscriptionInfo> getActiveSubscriptionInfoList()

Get the SubscriptionInfo(s) of the currently inserted SIM(s).

static int getDefaultDataSubscriptionId()

Returns the system's default data subscription id.

static int getDefaultSmsSubscriptionId()

Returns the system's default SMS subscription id.

static int getDefaultSubscriptionId()

Returns the system's default subscription id.

static int getDefaultVoiceSubscriptionId()

Returns the system's default voice subscription id.

boolean isNetworkRoaming(int subId)

Returns true if the device is considered roaming on the current network for a subscription.

void removeOnSubscriptionsChangedListener(SubscriptionManager.OnSubscriptionsChangedListener listener)

Unregister the SubscriptionManager.OnSubscriptionsChangedListener.

Inherited methods

From class java.lang.Object

Constants

ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED

added in API level 26
String ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED

Broadcast Action: The default sms subscription has changed. This has the following extra values:

EXTRA_SUBSCRIPTION_INDEX extra indicates the current default sms subscription index

Constant Value: "android.telephony.action.DEFAULT_SMS_SUBSCRIPTION_CHANGED"

ACTION_DEFAULT_SUBSCRIPTION_CHANGED

added in API level 26
String ACTION_DEFAULT_SUBSCRIPTION_CHANGED

Broadcast Action: The default subscription has changed. This has the following extra values:

The EXTRA_SUBSCRIPTION_INDEX extra indicates the current default subscription index

Constant Value: "android.telephony.action.DEFAULT_SUBSCRIPTION_CHANGED"

DATA_ROAMING_DISABLE

added in API level 22
int DATA_ROAMING_DISABLE

Indicates that data roaming is disabled for a subscription

Constant Value: 0 (0x00000000)

DATA_ROAMING_ENABLE

added in API level 22
int DATA_ROAMING_ENABLE

Indicates that data roaming is enabled for a subscription

Constant Value: 1 (0x00000001)

EXTRA_SUBSCRIPTION_INDEX

added in API level 26
String EXTRA_SUBSCRIPTION_INDEX

Integer extra used with ACTION_DEFAULT_SUBSCRIPTION_CHANGED and ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED to indicate the subscription which has changed.

Constant Value: "android.telephony.extra.SUBSCRIPTION_INDEX"

INVALID_SUBSCRIPTION_ID

added in API level 24
int INVALID_SUBSCRIPTION_ID

An invalid subscription identifier

Constant Value: -1 (0xffffffff)

Public methods

addOnSubscriptionsChangedListener

added in API level 22
void addOnSubscriptionsChangedListener (SubscriptionManager.OnSubscriptionsChangedListener listener)

Register for changes to the list of active SubscriptionInfo records or to the individual records themselves. When a change occurs the onSubscriptionsChanged method of the listener will be invoked immediately if there has been a notification.

Parameters
listener SubscriptionManager.OnSubscriptionsChangedListener: an instance of SubscriptionManager.OnSubscriptionsChangedListener with onSubscriptionsChanged overridden.

from

added in API level 22
SubscriptionManager from (Context context)

Get an instance of the SubscriptionManager from the Context. This invokes Context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE).

Parameters
context Context: to use.

Returns
SubscriptionManager SubscriptionManager instance

getActiveSubscriptionInfo

added in API level 22
SubscriptionInfo getActiveSubscriptionInfo (int subId)

Get the active SubscriptionInfo with the input subId.

Parameters
subId int: The unique SubscriptionInfo key in database.

Returns
SubscriptionInfo SubscriptionInfo, maybe null if its not active.

getActiveSubscriptionInfoCount

added in API level 22
int getActiveSubscriptionInfoCount ()

Returns
int the current number of active subscriptions. There is no guarantee the value returned by this method will be the same as the length of the list returned by getActiveSubscriptionInfoList().

getActiveSubscriptionInfoCountMax

added in API level 22
int getActiveSubscriptionInfoCountMax ()

Returns
int the maximum number of active subscriptions that will be returned by getActiveSubscriptionInfoList() and the value returned by getActiveSubscriptionInfoCount().

getActiveSubscriptionInfoForSimSlotIndex

added in API level 22
SubscriptionInfo getActiveSubscriptionInfoForSimSlotIndex (int slotIndex)

Get the active SubscriptionInfo associated with the slotIndex

Parameters
slotIndex int: the slot which the subscription is inserted

Returns
SubscriptionInfo SubscriptionInfo, maybe null if its not active

getActiveSubscriptionInfoList

added in API level 22
List<SubscriptionInfo> getActiveSubscriptionInfoList ()

Get the SubscriptionInfo(s) of the currently inserted SIM(s). The records will be sorted by getSimSlotIndex() then by getSubscriptionId().

Returns
List<SubscriptionInfo> Sorted list of the currently SubscriptionInfo records available on the device.

getDefaultDataSubscriptionId

added in API level 24
int getDefaultDataSubscriptionId ()

Returns the system's default data subscription id. On a voice only device or on error, will return INVALID_SUBSCRIPTION_ID.

Returns
int the default data subscription Id.

getDefaultSmsSubscriptionId

added in API level 24
int getDefaultSmsSubscriptionId ()

Returns the system's default SMS subscription id. On a data only device or on error, will return INVALID_SUBSCRIPTION_ID.

Returns
int the default SMS subscription Id.

getDefaultSubscriptionId

added in API level 24
int getDefaultSubscriptionId ()

Returns the system's default subscription id. For a voice capable device, it will return getDefaultVoiceSubscriptionId. For a data only device, it will return the getDefaultDataSubscriptionId. May return an INVALID_SUBSCRIPTION_ID on error.

Returns
int the "system" default subscription id.

getDefaultVoiceSubscriptionId

added in API level 24
int getDefaultVoiceSubscriptionId ()

Returns the system's default voice subscription id. On a data only device or on error, will return INVALID_SUBSCRIPTION_ID.

Returns
int the default voice subscription Id.

isNetworkRoaming

added in API level 22
boolean isNetworkRoaming (int subId)

Returns true if the device is considered roaming on the current network for a subscription.

Availability: Only when user registered to a network.

Parameters
subId int: The subscription ID

Returns
boolean true if the network for the subscription is roaming, false otherwise

removeOnSubscriptionsChangedListener

added in API level 22
void removeOnSubscriptionsChangedListener (SubscriptionManager.OnSubscriptionsChangedListener listener)

Unregister the SubscriptionManager.OnSubscriptionsChangedListener. This is not strictly necessary as the listener will automatically be unregistered if an attempt to invoke the listener fails.

Parameters
listener SubscriptionManager.OnSubscriptionsChangedListener: that is to be unregistered.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)