How to check phone in service State
<p>I am developing an app in which i m checking service state of the phone but when phone is in flight mode its not responding, or phone dont have sim then also its not working.  plz help me  code is below </p>

<pre><code>TelephonyManager telMng=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
        telMng.listen(new PhoneStateListener(){

                     @Override
                public void onServiceStateChanged (ServiceState serviceState){
                  super.onServiceStateChanged(serviceState);
                  String phonestate;
                 switch(serviceState.getState())
                  {
                 case ServiceState.STATE_IN_SERVICE:

                     Toast.makeText(getApplicationContext(), "phone is in service", Toast.LENGTH_LONG).show();
                     break;
                 case ServiceState.STATE_OUT_OF_SERVICE:
                     Toast.makeText(getApplicationContext(), "Phone is not in Service state", Toast.LENGTH_LONG).show();
                     break;
                     default:phonestate="Unknown";
                  }
                 /*

                  switch(serviceState.getState()){
                  case ServiceState.STATE_EMERGENCY_ONLY: phonestate ="STATE_EMERGENCY_ONLY"; ;break;
                  case ServiceState.STATE_IN_SERVICE: phonestate ="STATE_IN_SERVICE"; ;break;
                  case ServiceState.STATE_OUT_OF_SERVICE: phonestate ="STATE_OUT_OF_SERVICE"; ;break;
                  case ServiceState.STATE_POWER_OFF: phonestate ="STATE_POWER_OFF"; ;break;
                  default:phonestate = "Unknown";
                  } 
                  */  
            } 
        },  
        PhoneStateListener.LISTEN_SERVICE_STATE);

    }  
                                                                                                                                              i tried above code but its not working when phone is in flight mode or have not sim insert inside the phone what should i do plz help 
</code></pre>

<p>thanks in advance</p>
