How to check if sim card is installed (sim state) or cell signal strength on connected bluetooth devices programmatically?

59 views Asked by At

I'm developing a system dialer app for my android device, which can use a bluetooth-connected phone to make calls. So I need to know whether sim card is inserted or not or at least its cell signal level. I need this to show a special notification "there is no sim card".

1

There are 1 answers

2
xx90TDrgA On

You can use Telephony Manager and Phone State listener.

TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

tm.listen(new MyPhoneStateListener(), PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

class MyPhoneStateListener extends PhoneStateListener {

        @Override
        public void onSignalStrengthsChanged(SignalStrength signalStrength) {
            super.onSignalStrengthsChanged(signalStrength);
            int signalSupport = -signalStrength.getCdmaDbm();
            Log.d(getClass().getCanonicalName(), "gsm signal--> " + signalSupport);

            if (signalSupport < 90) {
                Log.d(getClass().getCanonicalName(), "Signal GSM : Good");

            } else if (signalSupport < 100) {
                Log.d(getClass().getCanonicalName(), "Signal GSM : Avarage");

            } else if (signalSupport < 110) {
                Log.d(getClass().getCanonicalName(), "Signal GSM : Weak");

            } else if (signalSupport < 120) {
                Log.d(getClass().getCanonicalName(), "Signal GSM : Very weak");

            } else { //120 -> no sim/signal
                Log.d(getClass().getCanonicalName(), "Signal GSM : Null");
            }
        }
    }