接收电话时,手电筒应用程序并不总是停止

时间:2016-07-12 13:14:17

标签: java android

每当收到来电或短信时,我都会尝试关闭手电筒。 它在某些设备(即HUAWEI设备)中运行良好 当我拒绝来电时,我的闪光灯不会熄灭。

相关代码:

 else{
        if(phoneManager.getCallState() == TelephonyManager.CALL_STATE_RINGING){
            if(prefs.getBoolean("call", true)) {
                Log.e("call", "start ->  type:" + prefs.getString("type", ""));
                String tp = prefs.getString("flash_type", "");
                if(!tp.equals(""))
                    flash.startCallFlashLight(getIndex(tp));

                else
                    flash.startCallFlashLight(1);

                lastState = TelephonyManager.CALL_STATE_RINGING;
            }
        }

        else if(lastState == TelephonyManager.CALL_STATE_RINGING &&
                ( phoneManager.getCallState() == TelephonyManager.CALL_STATE_OFFHOOK ||
                        phoneManager.getCallState() == TelephonyManager.CALL_STATE_IDLE)) {
            Log.e("call", "stop");
            flash.stopCallFlashLight();
            lastState = -1;
        }
    }

0 个答案:

没有答案