You should be able to do it quite simply with my Reflection library. Something like this though I haven't actually tried it. CellId and Lac only exist for GSM networks.
B4X:
Dim Obj1 As Reflector
Dim cid, lac As Int
Obj1.Target = Obj1.GetContext
Obj1.Target = Obj1.RunMethod2("getSystemService", "phone", "java.lang.String")
Obj1.Target = Obj1.RunMethod("getCellLocation") ' get a GsmCellLocation
cid = Obj1.RunMethod("getCid") ' gsm cell id
lac = Obj1.RunMethod("getLac") ' gsm location area code
Where? I've just tried and it works fine on my ZTE Blade. I had to add a GPS object to get the right permission in the manifest otherwise I got a security exception.
You are on a GSM network and have the radio on and connected?
Hello, the example above works, I would like to know where the library is Android "phone", I see only telephony; telephony.gsm; telephony.cdma.
Also because it uses "getCellLocation" to get GsmCellLocation?
why can not I get the example "getPsc" (with phone in CDMA mode)?
"Phone" is not an Android library, it is the Android constant Context.TELEPHONY_SERVICE used to obtain an instance of TelephonyManager.
I've already told you in this thread that you need a to register a PhoneStateListener to get signal strength. For that you will need a library as you can't do it with a Reflector object.
Check your unfiltered log to see what is there when the error occurs. Post the code that doesn't work and the exact text of the exception. We can't work without data.
Dim Obj1 As Reflector
Dim cid, lac As Int
Obj1.Target = Obj1.GetContext
Obj1.Target = Obj1.RunMethod2("getSystemService", "phone", "java.lang.String")
Obj1.Target = Obj1.RunMethod("getCellLocation") ' get a GsmCellLocation
cid = Obj1.RunMethod("getCid") ' gsm cell id
lac = Obj1.RunMethod("getLac") ' gsm location area code
Msgbox (cid,"GSM")
End Sub
It seems to crash on getCid.
java.lang.NullPointerException
at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:160)
at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod(Reflection.java:749)
at nl.openhanced.cellid.main._activity_create(main.java:223)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:105)
at nl.openhanced.cellid.main.afterFirstLayout(main.java:84)
at nl.openhanced.cellid.main.access$100(main.java:16)
at nl.openhanced.cellid.main$WaitForLayout.run(main.java:72)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException