Android Question How to Get Device Serial Number

lkching7

Member
Licensed User
There are a lot of Solution in Forum. But I try All, Still Cannot Get. Return Empty.
Do Anybody Have another Solution To Get This Serial Number ?

#IF JAVA
import java.lang.reflect.Method;

public static String gMS(String K) {
String serial = "-";
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class, String.class);
serial = (String) get.invoke(c, K, "-");
} catch (Exception ignored) {}
return serial;
}
#End If
Dim JV As JavaObject
JV.InitializeContext
Dim Result As String
Dim alist As List
alist.Initialize
alist.AddAll(Array As String("ril.serialnumber","ro.serialno"))
Dim str,K As String
For i = 0 To alist.Size-1
K=alist.Get(i)
str = JV.RunMethod("gMS" ,Array(K))
If str.Length>4 Then
If (str <> "00000000000") And (str <> "0123456789ABCDEF") Then
Result = str
Exit
End If
End If
Next
Return(Result)
Dim sn As String
Dim r As Reflector
Dim m As Object
Dim Types(1) As String

Types(0) = "java.lang.String"
r.target = r.CreateObject("android.os.SystemProperties")

m = r.GetMethod("get", Types)
sn = r.InvokeMethod(r.Target,m,Array("ril.serialnumber"))

Return sn
Capture.PNG
 

DonManfred

Expert
Licensed User
from stackoverflow

Since Android Q using Build.getSerial() gets a bit more complicated by requiring:

android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE (which can only be acquired by system apps), or for the calling package to be the device or profile owner and have the READ_PHONE_STATE permission. This means most apps won't be able to uses this feature. See the Android Q announcement from Google.

See Android SDK reference
It works if your app is a Systemapp or the Deviceowner app (kiosk mode).
As a normal app you probably do not get the permission needed. At least not in Android 7.1+

See
 
Top