测量牛轧糖及以上的信号强度

时间:2017-12-07 09:57:35

标签: android

我有一个测量信号强度的应用程序,并定期发送到数据库,它在所有棉花糖和下面的工作正常,我请求权限和一切(否则它不会在棉花糖上工作)。

我调试了android 7和8上的代码它到达了监听语句并且什么也没做,并且停止了程序的执行,我缺少什么

这是我的代码:

 try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-dd-M'T'HH:mm:ss", Locale.ENGLISH);
            Date strDate = sdf.parse(startingTime);

            if (new Date().after(strDate)) {
                if (enabled.equals("true")){

                    try {
                        telephonyManager.listen(psListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            else{
                //your_date_is_outdated = false;

                Log.wtf("before start" ,"no test");
            }

这是电话状态听众:

public class myPhoneStateListener extends PhoneStateListener {


    public void onSignalStrengthsChanged(SignalStrength signalStrength) {
        super.onSignalStrengthsChanged(signalStrength);

        signalSupport = signalStrength.getGsmSignalStrength();
        //signalSupport = signalStrength.getLevel();// bars
        Log.wtf(getClass().getCanonicalName(), "------ gsm signal --> " + signalSupport);

        if (signalSupport >= 30) {
            Log.wtf(getClass().getCanonicalName(), "Signal GSM : Good");


        } else if (signalSupport >= 20 && signalSupport < 30) {
            Log.wtf(getClass().getCanonicalName(), "Signal GSM : Avarage");


        } else if (signalSupport < 20 && signalSupport > 3) {
            Log.wtf(getClass().getCanonicalName(), "Signal GSM : Weak");


        } else if (signalSupport <= 3) {
            Log.wtf(getClass().getCanonicalName(), "Signal GSM : Very weak");
        }
        //<editor-fold desc="Signal Strength in different scales">
        /*signalStrengthDbm = getSignalStrengthByName(signalStrength, "getDbm");
        signalStrengthAsuLevel = getSignalStrengthByName(signalStrength, "getAsuLevel");
        Log.wtf(getClass().getCanonicalName(), "signalStrengthDbm : " +signalStrengthDbm);
        Log.wtf(getClass().getCanonicalName(), "signalStrengthAsuLevel : " +signalStrengthAsuLevel);*/
        //</editor-fold>

        Log.wtf("SIGNAL SUPPPORT IS " ,"sss "+ signalSupport);
        registerLocationUpdates(signalSupport);
        telephonyManager.listen(psListener, PhoneStateListener.LISTEN_NONE);

    }

    private int getSignalStrengthByName(SignalStrength signalStrength, String methodName) {
        try
        {
            Class classFromName = Class.forName(SignalStrength.class.getName());
            java.lang.reflect.Method method = classFromName.getDeclaredMethod(methodName);
            Object object = method.invoke(signalStrength);
            return (int)object;
        }
        catch (Exception ex) {
            return INVALID;
        }
    }

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        super.onCallStateChanged(state, incomingNumber);
        Log.wtf("onCallStateChanged", "------ gsm signal --> " + signalSupport);
    }
}

0 个答案:

没有答案