Hi KZero, we tested your code, but stops in this line: str = JV.RunMethod("gMS" ,Array(K)). The error message is this:
cys_getdevoceserial (B4A line: 1993)
str = JV.RunMethod("gMS" ,Array(K))
java.lang.RuntimeException: Method: gMS not found in: CYS.RUTEO.main
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:366)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:119)
at CYS.RUTEO_getdevoceserial(cys.java:2590)
at CYS.RUTEO_parametrosiniciales(cys.java:3479)
at CYS.RUTEOmain._activity_create(main.java:1066)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at CYS.RUTEOmain.afterFirstLayout(main.java:102)
at CYS.RUTEOmain.access$000(main.java:17)
at CYS.RUTEOmain$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Thanks in advance for your help.
i'm using this code for long time and it still working (tested on samsung S10 android 9)
it using SystemProperties so no dangerous permissions needed
Sub GetDevoceSerial As String
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)
End Sub
#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