I'm trying to obtain an instance of ServiceState in my Activity. But how am i supposed to do this? There is no static method to obtain an instance or any method on any service that returns an ServiceState instance. There is the TelephonyManager.listen() call. But i want to get the ServiceState instance when i want, not when android calls my listener because something changed. The documentation of ServiceState can be found here: http://developer.android.com/reference/android/telephony/ServiceState.html
Some calls are not available for the developer. Period.
If you want that kind of info, you will have a PhoneStateListener
like this example.
I haven't tried this yet but i'm going to have to since this sort of funcitonality is key to my app. I'll let you know how it goes, but here's the idea:
From the API (instance method of TelephonyManager):
public void listen (PhoneStateListener listener, int events) Since: API Level 1 Registers a listener object to receive notification of changes in specified telephony states.
To register a listener, pass a PhoneStateListener and specify at least one telephony state of interest in the events argument. At registration, and when a specified telephony state changes, the telephony manager invokes the appropriate callback method on the listener object and passes the current (udpated) values.
You could just register a listener and keep it, and then get the callback to save the reported state in your Activity upon each change so that your app could just refer to the Activity field every time it needs to check. Alternatively you could keep registering and throwing out listeners every time you want a state measurement, but I think that would waste more system resources than just keeping one on.