# TelephonyManagerCompat

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/telephony/TelephonyManagerCompat.java+class:androidx.core.telephony.TelephonyManagerCompat) Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/core#1.6.0)

*** ** * ** ***


```
public class TelephonyManagerCompat
```

<br />

*** ** * ** ***

Helper for accessing features in `https://developer.android.com/reference/android/telephony/TelephonyManager.html`.

## Summary

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `@https://developer.android.com/reference/androidx/annotation/RequiresPermission(value = https://developer.android.com/reference/android/android.Manifest.permission.html#READ_PHONE_STATE) https://developer.android.com/reference/androidx/core/telephony/TelephonyManagerCompat#getImei(android.telephony.TelephonyManager)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/telephony/TelephonyManager.html telephonyManager)` Returns the IMEI (International Mobile Equipment Identity) associated with the subscription id of the given TelephonyManager, or null if not available. |
| `static int` | `https://developer.android.com/reference/androidx/core/telephony/TelephonyManagerCompat#getSubscriptionId(android.telephony.TelephonyManager)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/telephony/TelephonyManager.html telephonyManager)` Return the subscription ID the TelephonyManager was created with (via `https://developer.android.com/reference/android/telephony/TelephonyManager.html#createForSubscriptionId(int)`) if applicable, and otherwise the default subscription ID. |

## Public methods

### getImei

Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/core#1.6.0)

```
@RequiresPermission(value = android.Manifest.permission.READ_PHONE_STATE)
public static @Nullable String getImei(@NonNull TelephonyManager telephonyManager)
```

Returns the IMEI (International Mobile Equipment Identity) associated with the subscription id of the given TelephonyManager, or null if not available.

Below Android 10, this API requires any of:

- the caller holds the READ_PHONE_STATE permission
- the caller has carrier privileges (see `https://developer.android.com/reference/android/telephony/TelephonyManager.html#hasCarrierPrivileges()`)

On Android 10 and above, this API requires any of:

- the caller holds the READ_PRIVILEGED_PHONE_STATE permission
- the caller is the device or profile owner and holds the READ_PHONE_STATE permission
- the caller has carrier privileges (see `https://developer.android.com/reference/android/telephony/TelephonyManager.html#hasCarrierPrivileges()`)
- the caller is the default SMS role holder (see `https://developer.android.com/reference/android/app/role/RoleManager.html#isRoleHeld(java.lang.String)`)
- the caller holds the USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER permission

### getSubscriptionId

Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/core#1.6.0)

```
public static int getSubscriptionId(@NonNull TelephonyManager telephonyManager)
```

Return the subscription ID the TelephonyManager was created with (via `https://developer.android.com/reference/android/telephony/TelephonyManager.html#createForSubscriptionId(int)`) if applicable, and otherwise the default subscription ID.