Hey everyone,
After a request made by bluejay at this page , I developed the PhoneStateListener Library.
With the PhoneStateListener, you are able to retrieve several kinds of information when something happens on your phone, like someone is calling, when you mobile phone signal strength changes, celllocation changes, etc.
PhoneStateListener
Author: XverhelstX
Version: 1.3
* When onSignalStrengthsChanged is called, you can automatically use all the get methods (like getGsmSignalStrength, getEvdoEcio(), ...).
* A lot of details is outputted to the filtered B4A logs, so don't forget to check that out too.
The best thing, is that it is very easy to use and implement in your app.
Just add a service and copy the following:
Don't forget to start the service with StartService and stop with Stopservice.
The attachment contains a sample and the library files.
More information can be found here:
PhoneStateListener | Android Developers
Feedback, criticism and found bugs are welcome and will be fixed asap.
Tomas
After a request made by bluejay at this page , I developed the PhoneStateListener Library.
With the PhoneStateListener, you are able to retrieve several kinds of information when something happens on your phone, like someone is calling, when you mobile phone signal strength changes, celllocation changes, etc.
PhoneStateListener
Author: XverhelstX
Version: 1.3
- PhoneStateListener
Fields:- LISTEN_CALL_FORWARDING_INDICATOR As Int
- LISTEN_CALL_STATE As Int
- LISTEN_CELL_LOCATION As Int
- LISTEN_DATA_ACTIVITY As Int
- LISTEN_DATA_CONNECTION_STATE As Int
- LISTEN_MESSAGE_WAITING_INDICATOR As Int
- LISTEN_NONE As Int
- LISTEN_SERVICE_STATE As Int
- LISTEN_SIGNAL_STRENGTHS As Int
- Initialize (EventName As String, EnableLogging As Boolean)
Initializes the PhoneStateListener.
EventName - Events subs prefix. - isGSM As Boolean
- objCellLocation As Object
Returns the CellLocation.
CellLocation has a value when onCellLocationChanged is called.
You can work with this object in the Reflector library.
Return type: @return: - objServiceState As Object
Returns the ServiceState.
ServiceState1 has a value when onServiceStateChanged is called.
You can work with this object in the Reflector library.
Return type: @return: - objSignalStrength As Object
Returns the SignalStrength.
SignalStrength has a value when onSignalStrengthsChanged is called.
You can work with this object in the Reflector library.
Return type: @return: - startListening
Starts listening for all PhoneStateListener Events.
Use startListeningForEvent for specific events. - startListeningForEvent (Event As Int)
Starts listening for specific event in the phone.
See the LISTEN_Attributes - stopListening
Stops listening for all PhoneStateListener Events.
Use stopListeningForEvent to stop specific events. - stopListeningForEvent
Stops listening for PhoneStateListener Events called from StartListeningForEvent.
- android.permission.ACCESS_COARSE_LOCATION
- android.permission.ACCESS_COARSE_UPDATES
- android.permission.ACCESS_NETWORK_STATE
- android.permission.CHANGE_NETWORK_STATE
- android.permission.READ_PHONE_STATE
- CdmaDbm As Int [read only]
Get the CDMA RSSI value in dBm - CdmaEcio As Int [read only]
Get the CDMA Ec/Io value in dB*10 - CellLocation As String [read only]
Gets the cell location in a string. - EvdoDbm As Int [read only]
Get the EVDO RSSI value in dBm - EvdoEcio As Int [read only]
Get the EVDO Ec/Io value in dB*10 - EvdoSnr As Int [read only]
Get the signal to noise ratio. - GsmBitErrorRate As Int [read only]
Get the GSM bit error rate (0-7, 99) as defined in TS 27.007 8.5 - GsmSignalStrength As Int [read only]
Get the GSM Signal Strength, valid values are (0-31, 99) as defined in TS 27.007 8.5
* When onSignalStrengthsChanged is called, you can automatically use all the get methods (like getGsmSignalStrength, getEvdoEcio(), ...).
* A lot of details is outputted to the filtered B4A logs, so don't forget to check that out too.
The best thing, is that it is very easy to use and implement in your app.
Just add a service and copy the following:
B4X:
'Service module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
'Declares the phone state listener
Dim PSL As PhoneStateListener
End Sub
Sub Service_Create
'Initializes the PhoneStateListener.
'All data is also outputted to the filtered log field.
PSL.Initialize("PSL")
'Starts listening
PSL.startListening()
ToastMessageShow(PSL.CellLocation,False)
'Remember: Find all information about the returns here:
' http://developer.android.com/reference/android/telephony/PhoneStateListener.html
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
Sub Service_Destroy
End Sub
' Callback invoked when the call-forwarding indicator changes.
Sub PSL_onCallForwardingIndicatorChanged(cfi As Boolean)
End Sub
'Callback invoked when device call state changes.
'Idle = 0
'Ringing = 1
'OFFHook = 2
Sub PSL_onCallStateChanged (State As Int, incomingNumber As String)
End Sub
' Callback invoked when device cell location changes.
Sub PSL_onCellLocationChanged(Location As String)
End Sub
'Callback invoked when data activity state changes.
Sub PSL_onDataActivity(Direction As Int, strDirection As String)
End Sub
'Callback invoked when connection state changes.
Sub PSL_onDataConnectionStateChanged(state As Int, Connectionstate As String)
End Sub
'Callback invoked when the message-waiting indicator changes.
Sub PSL_onMessageWaitingIndicatorChanged(mwi As Boolean)
End Sub
'Callback invoked when device service state changes.
Sub PSL_onServiceStateChanged(State As Int, strState As String)
End Sub
'Callback invoked when network signal strengths changes.
'you can use getCDma, etc to get the network connection.
Sub PSL_onSignalStrengthsChanged (signalStrength As String)
ToastMessageShow(signalStrength, False)
ToastMessageShow(PSL.CdmaDbm, False)
End Sub
'Remember: Find all information about the returns here:
' http://developer.android.com/reference/android/telephony/PhoneStateListener.html
Don't forget to start the service with StartService and stop with Stopservice.
The attachment contains a sample and the library files.
More information can be found here:
PhoneStateListener | Android Developers
Feedback, criticism and found bugs are welcome and will be fixed asap.
Tomas
Attachments
Last edited: