How to read the Serial Number on Datalogic Android Devices

Serial Number and “non-resettable device identifiers”

With a path that started with Android 8 and culminated in Android 11, in order to protect privacy and traceability of retail users, Google progressively restricted, then prevented the third party apps to access the non-resettable device identifiers.

API level 26, Build.SERIAL deprecation: (Build  |  Android Developers)
API level 26, new Build.getSerial() (today restricted): (Build  |  Android Developers)
API level 28 privacy changes: (Behavior changes: apps targeting API level 28+  |  Android Developers)
API level 29, restriction of non-resettable device ids: (Privacy changes in Android 10  |  Android Developers)

According with the Best practices for unique identifiers Google’s article, in most use cases the third party apps can avoid using hardware identifiers, such as SSAID (Android ID) and other, without limiting required functionality.

The full access to that information is reserved to device or profile owner app, apps with special carrier permissions and apps that have the READ_PRIVILEGED_PHONE_STATE privileged permission.
(See Best practices for unique identifiers  |  Android Developers.)

However, in the enterprise and B2B world, many legacy customer’s application still require to access those information for example for licensing, tracing or device inventory reasons.

Android 8 and 9
Starting from SDK 1.25 (see FWs compatibility table at Datalogic Android SDK | Technical Documentation), a new AppManager class has been introduced to allow apps to programmatically grant the required permissions to any app via Datalogic SDK.
The user can rely on that class for reading the SerialNumber, by adding to the manifest the required permission and programmatically granting:

Up to Android 9

 <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

From Android 10 (privileged application only)

 <uses-permission android:name="android.permission.READ_PRIVILIGED_PHONE_STATE"/>

Then into the code (SDK 1.25 required):

val am = AppManager(application.applicationContext)` 
ret = am.grantAllPermissions(this.packageName)`

    fun getSerial(): String
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            //Android 9 (or Android 10, privileged application only)
            return Build.getSerial()
        else    {
            //Android 8 and earlier
            return Build.SERIAL)

Android 10

On Android 10, since only privileged apps can access the Build.getSerial() system method, Datalogic SDK 1.28 (see SDK/ FWs compatibility table) has introduced a new “SERIAL_NUMBER” static fields to the class .

//Android 10, SDK 1.28, any app

Xamarin SDK
Equivalent features will be released for Xamarin SDK with an update currently planned for the end of October 2021.

Simone Callegari
Mobile Products L3 Specialist SW Engineer

1 Like

A new version of Datalogic Xamarin SDK has been released on NuGet on Dec 6th, 2021 to add the capabilities to retrieve the Serial Number, the Part Number and many other features.
These are the Release Notes of the the Datalogic Xamarin SDK v.1.29 8975, with the list of all the new features included.

Simone Callegari
Datalogic Mobile Products Specialist - L3 Software Engineer