05-30-2012 09:36 AM - edited 05-31-2012 06:41 AM
I have a problem determining the best way to monitor connection changes and types using the available APIs. Originally, I wanted to listen for change in connection so that I could reliably monitor data usage on the phone by counting bytes. This does not seem to be possible, however I still want to offer some information to the user by counting total bytes, and also some approximation of bytes transported over Wi-Fi. This, specifically, may not be the best approximation, so I am asking if anyone can tell me the best way to monitor Wi-Fi connection change, and if there is another, better way to approximate free/paid data usage.
Further info:
I have found the following listeners that may be of use. As you can see, there's quite a lot to choose from and I'm sure there's a right and wrong way to do this...
Listeners
system.GlobalEventListener [API ?]
Can be used for service book changes as described here.
====> Application.addGlobalEventListener(GlobalEventListener) [API ?]
system.RadioListener [API 3.6.0]
No callbacks or usage documented.
====> Application.addRadioListener(int WAFFilter, RadioListener) [API 4.2.1]
system.RadioStatusListener [API 3.6.0]
Inherits from system.RadioListener. Deals with PDP contexts. Partly deprecated.
Type flags include:
NETWORK_SERVICE_* (see below)
servicebook.ServiceRoutingListener [API 4.1.0]
Monitors data service routing changes (serial bypass - phone hooked up to a PC - or Bluetooth).
====> ServiceRouting.addListener(ServiceRoutinglistener) [API 4.1.0]
system.CoverageStatusListener [API 4.2.0]
Aggregate-only coverage info for WAFs, Bluetooth and serial bypass. Docs recommend usage of Application.addRadioListener(int WAFFilter, RadioListener) for WAF-specific radio events and servicebook.ServiceRouting.addListener(ServiceRout
Type flags include:
COVERAGE_BIS_B
COVERAGE_DIRECT
COVERAGE_MDS
COVERAGE_NONE
====> CoverageInfo.addListener(system.CoverageStatusListener) [API 4.2.0]
io.transport.CoverageStatusListener [API 6.0.0]
Information about transport types. A change in coverage can have several sources, including the addition or deletion of service books, changes to signal strength, transport specific communication requirements, and others.
Type flags include:
TRANSPORT_BIS_B
TRANSPORT_MDS
TRANSPORT_TCP_CELLULAR
TRANSPORT_TCP_WIFI
TRANSPORT_WAP
TRANSPORT_WAP2
====> TransportInfo.addListener(CoverageStatusListener) [API 6.0.0]
system.WLANListener [API 4.3.0]
====> WLANInfo.addListener(WLANListener) [API 4.3.0]
Direct Calls:
For use during scheduled coverage checks:
RadioInfo:
==> system.RadioInfo.getNumberOfPacketsSent() [API 4.0.0]
==> system.RadioInfo.getNumberOfPacketsReceived() [API 4.0.0]
==> system.RadioInfo.getActiveWAFs() [API 4.2.1]
Only indicates the option is enabled, not that there is a WiFi network connected.
Flags returned:
WAF_3GPP
WAF_CDMA
WAF_IDEN
WAF_WLAN
==> system.RadioInfo.getNetworkService(int waf) [API 4.5.0]
Flags returned:
NETWORK_SERVICE_DATA
NETWORK_SERVICE_DIRECT_CONNECT
NETWORK_SERVICE_E911_CALLBACK_MODE
NETWORK_SERVICE_EDGE
NETWORK_SERVICE_EMERGENCY_ONLY
NETWORK_SERVICE_EVDO
NETWORK_SERVICE_EVDO_ONLY
NETWORK_SERVICE_EVDO_REV0
NETWORK_SERVICE_EVDO_REV0_ONLY
NETWORK_SERVICE_EVDO_REVA
NETWORK_SERVICE_EVDO_REVA_ONLY
NETWORK_SERVICE_GAN
NETWORK_SERVICE_IN_CITY_ZONE
NETWORK_SERVICE_IN_HOME_ZONE
NETWORK_SERVICE_MODEM_MODE_ENABLED
NETWORK_SERVICE_ROAMING
NETWORK_SERVICE_ROAMING_OFF_CAMPUS
NETWORK_SERVICE_SDGC
NETWORK_SERVICE_SUPPRESS_ROAMING
NETWORK_SERVICE_UMTS
NETWORK_SERVICE_VOICE
==> system.RadioInfo.isDataServiceOperational(int wafs) [API 6.0.0]
TransportInfo:
==> io.transport.TransportInfo.getCoverageStatus() [API 6.0.0]
WLANInfo:
==> system.WLANInfo.getWLANState() [API 4.3.0]
edit: formatting, flags
05-30-2012 11:41 AM
05-30-2012 11:53 AM
05-31-2012 02:57 AM
05-31-2012 04:33 PM
06-01-2012 02:39 AM