SoFunction
Updated on 2025-04-07

How to get device serial number for Android applications

Software and hardware environment

  1. Macbook Pro MGX 72
  2. Android studio 2.1.2
  3. Android 5.1.1

Preface

The previous article introduced how to obtain the MAC address of ethernet. For manufacturers, in addition to the MAC number, there is another data that is also very important, that is, the machine serial number, which is determined when the machine leaves the factory and is also the main identifier. Each machine is different.

To obtain the serial number, you must first know where the serial number comes from and where it is written. Generally speaking, the serial number is a string defined by the manufacturer itself. Some digits in the string have different meanings, such as the manufacturer's ID, factory time, machine type, etc. In addition, the serial number defined by the operator almost follows this rule.

Recording of serial numbers at factory

This is what the burning program does. First of all, you need to design a flashmap. Generally speaking, an independent partition will be taken out to store these solidified information. Once this information is burned, it will not be changed. Android images, etc. are also stored in such partitions. The Android system burning is generally done using fastboot, which is simple, convenient and fast.

uboot get serial number

After the serial number is written to flash, uboot has a way to get it, and then uboot can pass it to the kernel in the form of (key, value). Of course, the parameters passed to the kernel are not only the serial number, so if you need to pass some custom data, you can also implement it in this way. In Android, what is passed is.

Get the serial number in android app

To sum up, to get the serial number in the App is actually to get a certain value in the Android ro attribute. Once you understand this, things will be easier. See the following code implementation

private String getSerialNumber(){

  String serial = null;

  try {

    Class<?> c =("");

    Method get =("get", );

    serial = (String)(c, "");

  } catch (Exception e) {

    ();

  }

  return serial;

}

A little extension

In Android, (hardware) is the logo of each chip manufacturer. In this file, you can set some system attribute information through the setprop command, such as mac, manufacturer ID, etc., and then in Android applications, you can also obtain the corresponding value through the above methods.

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.