Build.GetSerial Method

Definition

Gets the hardware serial number, if available.

[Android.Runtime.Register("getSerial", "()Ljava/lang/String;", "", ApiSince=26)]
[Android.Runtime.RequiresPermission("android.permission.READ_PRIVILEGED_PHONE_STATE")]
public static string? GetSerial ();
[<Android.Runtime.Register("getSerial", "()Ljava/lang/String;", "", ApiSince=26)>]
[<Android.Runtime.RequiresPermission("android.permission.READ_PRIVILEGED_PHONE_STATE")>]
static member GetSerial : unit -> string

Returns

The serial number if specified.

Attributes

Remarks

Gets the hardware serial number, if available.

<p class="note"><b>Note:</b> Root access may allow you to modify device identifiers, such as the hardware serial number. If you change these identifiers, you can not use key attestation to obtain proof of the device's original identifiers. KeyMint will reject an ID attestation request if the identifiers provided by the frameworks do not match the identifiers it was provisioned with.

Starting with API level 29, persistent device identifiers are guarded behind additional restrictions, and apps are recommended to use resettable identifiers (see Best practices for unique identifiers). This method can be invoked if one of the following requirements is met: <ul> <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this is a privileged permission that can only be granted to apps preloaded on the device. <li>If the calling app has carrier privileges (see android.telephony.TelephonyManager#hasCarrierPrivileges) on any active subscription. <li>If the calling app is the default SMS role holder (see android.app.role.RoleManager#isRoleHeld(String)). <li>If the calling app is the device owner of a fully-managed device, a profile owner of an organization-owned device, or their delegates (see android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()). </ul>

If the calling app does not meet one of these requirements then this method will behave as follows:

<ul> <li>If the calling app's target SDK is API level 28 or lower and the app has the READ_PHONE_STATE permission then Build#UNKNOWN is returned.</li> <li>If the calling app's target SDK is API level 28 or lower and the app does not have the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or higher, then a SecurityException is thrown.</li> </ul>

Java documentation for android.os.Build.getSerial().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to