Android Question Serial-number of Android-Device?

W. Graf

Member
Licensed User
Longtime User
Hi!

I need to find out the device-ID (serial-number of my android-device). On multiple forums, I found the following lines, which should deliver the information:

B4X:
try {
  Class<?> c = Class.forName("android.os.SystemProperties");
  Method get = c.getMethod("get", String.class);
  serial_no = (String) get.invoke(c, "ro.serialno");
  System.out.println("Device serial ID : " + serial_no);
} catch (Exception e) {
  System.out.println("Some error occured : " + e.getMessage());
}


See also:
http://stackoverflow.com/questions/2322234/how-to-find-serial-number-of-android-device
http://www.coderzheaven.com/2011/07...ice-id-or-serial-number-of-an-android-device/

I converted this code into B4A. I'm getting a string (maybe hex-number?), but this string doesn't match with the string, which I can find in my android-settings (Options - Info - Status). The real device ID consists of letters and numbers (it is no hex-number!)
Do you know, how I can get the device-id (not IMEI!)?

Here is my source-code:

B4X:
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("ro.serialno"))

Label3.Text = sn


Thank you in advance!
BR Wolfgang
 

W. Graf

Member
Licensed User
Longtime User
Thank you for your reply.
I already read this thread, but it returns the same serial number like my Code (see above).

Up to now, I don't know what kind of numbers this code returns. But it doesn't match with the number, which I can find in my settings on the mobile phone (I tried it on a Samsung S4 mini).
 
Upvote 0

W. Graf

Member
Licensed User
Longtime User
Hi again!

I found a new method on this site:
http://stackoverflow.com/questions/...-samsung-device-from-within-app-on-the-device

I translated it to B4A:
B4X:
Sub GetManufacturerSerialNumber As String
    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
End Sub

On Samsung S4 mini, it works perfectly (Android 4.2.2 and Android 4.4.4). But on a Nexus 7 (Android 6, no SIM module), it returns no serial number. Instead of, I can get the serial number via another method (static field):
B4X:
Dim r1 As Reflector
Label7.Text = "Build.SERIAL: " & r1.GetStaticField("android.os.Build", "SERIAL" )
(This method was extracted from:
https://www.b4x.com/android/forum/t...ue-id-alternative-to-phoneid.14759/#post83638
)
This method (static field) returns a value on Samsung S4 mini too. But the value doesn't match with the serial number I found in the Android Settings. I don't know, what Kind of value this is.

On a LG 440 smart phone, GetManufacturerSerialNumber() Returns an empty string. The second method (static field) Returns a Long alphanumeric string, but the string doesn't match with the Serial#, which is printed on the backside of the phone. In the Android Settings, I couldn't find a Serial#. It seems, that there is no way, which return always and on every device the correct Serial#?! :-(

Does anybody has any ideas?

If you want, you can test GetManufacturerSerialNumber() on your device and post your results to this thread (with additional Information, what kind of device you are using, SIM module Y/N, Android Version)?

Thank you!
BR Wolfgang
 
Upvote 0

Ferraz71

Member
Licensed User
Longtime User
Nice Job... with your method i can get the SystemProperties,

but how can i set the properties value like this:

SystemProperties.set ("Ctl.start", "my service in init.rc");
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I tried the GetManufactureSerialNumber on my Samsung S5 (Sm-S902L - StraightTalk Cell Phone) Android 4.4.2 and got 0
on my Samsung Galaxy Tab-2 (SM-T210R - WifFi Only) Android 4.4.2 got a number RF2D60....

None of these numbers match anything I can find on my devices
 
Upvote 0
Top