Cell Tower CellID

larrytango

Member
Licensed User
Longtime User
Hello , im wishing to make an app that will do things based on what cell tower im connected to , is it possible using b4a to get the current cellid?
 
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.
Code:
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
 
Upvote 0
Works on my Nexus One, had to add a GPS object. Now going to see if I can get the signalstrength.
 
Upvote 0
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)?

how i can use reflect with this :

http://developer.android.com/reference/android/telephony/SignalStrength.html

thanks

Regards

MArco
 
Last edited:
Upvote 0
"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.

The getPsc method does not exist for CdmaCellLocation.
 
Upvote 0
CellId

Agraham,

it worked but now with GPS added I get the same exception error again. Any suggestions?

Cheers,
 
Upvote 0
getCid

Hi,

This is the code i use:

Sub Activity_Create(FirstTime As Boolean)

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
 
Upvote 0
Also make sure you are currently on a gsm network eg


nt = ph.GetNetworkType
Select nt
Case "EDGE", "GPRS", "HSDPA", "HSPA", "HSUPA", "UMTS"
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
End Select

bluejay
 
Upvote 0
Vendor-RIL?

Is it possible to talk directly to the vendor-RIL (Radio Interface Layer)?
I need to send commands to them and also need to get responses.
 
Upvote 0
Back
Top