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?
 

agraham

Expert
Licensed User
Longtime User
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
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Works on my Nexus One, had to add a GPS object. Now going to see if I can get the signalstrength.
 
Upvote 0

spillermarco

Member
Licensed User
Longtime User
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

agraham

Expert
Licensed User
Longtime User
"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

bluedude

Well-Known Member
Licensed User
Longtime User
CellId

Agraham,

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

Cheers,
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
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

bluejay

Active Member
Licensed User
Longtime User
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

Roadrunner

Member
Licensed User
Longtime User
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
Top