Android still detects cellular signal strength while no cellular network connected

别等时光非礼了梦想. 提交于 2019-12-06 16:52:59

I have just implemented n Run Code:

package com.example.sanketprabhu.gsmsignalstrength;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity
    {
        TelephonyManager Tel;
        MyPhoneStateListener MyListener;

        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            MyListener   = new MyPhoneStateListener();
            Tel       = ( TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE);
            Tel.listen(MyListener ,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
        }

         @Override
        protected void onPause()
        {
            super.onPause();
            Tel.listen(MyListener, PhoneStateListener.LISTEN_NONE);
        }

          @Override
        protected void onResume()
        {
            super.onResume();
            Tel.listen(MyListener,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
        }

        public  class MyPhoneStateListener extends PhoneStateListener
        {
            /* Get the Signal strength from the provider, each tiome there is an update */
            @Override
            public void onSignalStrengthsChanged(SignalStrength signalStrength)
            {
                super.onSignalStrengthsChanged(signalStrength);
                Toast.makeText(getApplicationContext(), "Go to Firstdroid!!! GSM Cinr = " 
                        + String.valueOf(signalStrength.getGsmSignalStrength()), Toast.LENGTH_SHORT).show();
            }

        }

    }

It works for me.

Here I have attached Some Screen shots.

Yo are right:Values in betn 0-31 & 99

Unfortunately I am in office where signal strength is low, but works

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!