为什么在3g模式下必须设置一个侦听器才能获得单个当前电池的信号强度?

我们使用NeghbouringcellInfo类获得neighbouringcell的信号强度吗?

为什么我们不能这样获得当前细胞的信号强度?

最佳答案

试试下面的代码:

    ConnectivityManager manager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
    boolean is3g = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();


    if (is3g) {
        myListener = new MyPhoneStateListener();
        TelephonyManager telManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
        telManager.listen(myListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    }

    private class MyPhoneStateListener extends PhoneStateListener {
        public int singalStenths = 0;
        @Override
        public void onSignalStrengthsChanged(SignalStrength signalStrength){
            super.onSignalStrengthsChanged(signalStrength);
            int singalStrength  = signalStrength.getGsmSignalStrength();
            singalStenths = signalStrength.getGsmSignalStrength();
            System.out.println("----- gsm strength" + singalStrength );
            System.out.println("----- gsm strength" + singalStenths );

            if (singalStenths > 30) {
                signalstrength.setText("Signal Str : Good");
                signalstrength.setTextColor(getResources().getColor(R.color.good));
            }
            else if(singalStenths > 20 && singalStenths < 30) {
                signalstrength.setText("Signal Str : Average");
                 signalstrength.setTextColor(getResources().getColor(R.color.average));
            }
            else if(singalStenths < 20) {
                signalstrength.setText("Signal Str : Weak");
                 signalstrength.setTextColor(getResources().getColor(R.color.weak));
            }
        }
    };

关于android - android 3G信号强度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12674216/

10-09 06:14