tags:

views:

37

answers:

2

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

A: 

Some calls are not available for the developer. Period.

If you want that kind of info, you will have a PhoneStateListener like this example.

Macarse
Yeah well, that's exactly what i described and what i don't want to do ;) i need to check ServiceState when my Activity launches for example.
Goddchen
You will have to think of a workaround with the `PhoneStateListener`.
Macarse
I would have to change something, like activating flight mode or something like that. But i don't want to change stuff that the user don't want me to change...
Goddchen
A: 

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.

Sam Svenbjorgchristiensensen