2

I am trying to make the flashlight turn off whenever a call or SMS message is received. It works perfectly but in some devices (i.e. HUAWEI devices) my flash light doesn't turn off when I reject the incoming call.

Relevant code:

 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;
        }
    }
Blubberguy22
  • 1,344
  • 1
  • 17
  • 29
bmm
  • 73
  • 1
  • 7
  • if the code is working in most part of devices, please post stacktrace you have in the problematic ones – Jordi Castilla Jul 12 '16 at 13:16
  • my logcat dont show anything – bmm Jul 12 '16 at 13:18
  • mmm... you mean anything strange, because android stacktrace is quite vervosing `xD`, you tried connecting problematic devices to the developing computer?? are the states updated correctly? – Jordi Castilla Jul 12 '16 at 13:18
  • what is android stacktrace? is it part of my IDM to show my problem? Or you mean to debug this part of code? – bmm Jul 12 '16 at 13:20
  • which ide are you using? Eclipse? AndroidStudio? http://stackoverflow.com/questions/7841232/java-android-how-to-print-out-a-full-stack-trace – Jordi Castilla Jul 12 '16 at 13:21
  • android studio i ues – bmm Jul 12 '16 at 13:25
  • you KNOW , it doesn't go to this part of my code to apply , so I couldn't get my error to show.else if(lastState == TelephonyManager.CALL_STATE_RINGING && ( phoneManager.getCallState() == TelephonyManager.CALL_STATE_OFFHOOK || phoneManager.getCallState() == TelephonyManager.CALL_STATE_IDLE)) – bmm Jul 12 '16 at 13:26
  • well, this if not an error seems an unexpected behaviour, searching a bit, I found [this](http://stackoverflow.com/a/22088691/3850595) what says: *PhoneStateListener can not work on many device especially on HUAWEI and ZTE.* and provide a workaround... let me know if you succeed ;) – Jordi Castilla Jul 13 '16 at 09:36

0 Answers0