Hi!

I'm trying to get current service state of my phone (IN_SERVICE,
OUT_OF_SERVICE, EMERGENCY_ONLY, POWER_OFF). It can be easily fetched
with getState() method of ServiceState when a onServiceStateChanged
(ServiceState serviceState) callback is invoked:

public class ServiceStateListener extends PhoneStateListener{
@Override
            public void onServiceStateChanged(ServiceState serviceState) {
                switch(serviceState.getState()){
                                case ServiceState.STATE_IN_SERVICE:
                                        Log.i("Listener", "In Service");
                        break;
                                case ServiceState.STATE_EMERGENCY_ONLY:
                                        Log.i("Listener", "Emergency");
                                        break;
                                case ServiceState.STATE_OUT_OF_SERVICE:
                                        Log.i("Listener", "Out Of Service");
                                        break;
                                case ServiceState.STATE_POWER_OFF:
                                        Log.i("Listener", "Phone Off");
                                        break;
                        }
        }

But if you explicitly create a ServiceState object and try to get it's
state. It's always Out Of Service (returns 1), no matter what state
your phone is in right now:

@Override
public void onCreate() {
        ServiceState serviceState = new ServiceState();
        Log.i("onCreate", Integer.toString(serviceState.getState()));
}

I don't have much experience with Android. Any help is appreciated.
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to