我正在開發一個應用程序,其中我檢查電話的服務狀態,但是當電話處於飛行模式時它沒有響應,或者電話不具有SIM,那麼它也不工作。 plz幫助我的代碼是如何檢查服務中的電話狀態
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
感謝低於事先
謝謝@DevfaR它現在的工作。再次感謝我的心底 – IPL10
投票。這不是正確的答案。這隻會告訴你是否插入SIM卡,而不是SIM卡是否在服務中 – ComputerEngineer88