Check this
http://stackoverflow.com/questions/4846271/broadcastreceiver-to-obtain-servicestate-information/10005023#10005023
 

On Wednesday, January 6, 2010 5:59:42 PM UTC+5:30, Coby wrote:
>
> 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