This is only because In some mobile (SdkVersion 11 and above ) , its not going through TelephonyManager.CALL_STATE_OFFHOOK
and TelephonyManager.CALL_STATE_RINGING
and directly call TelephonyManager.CALL_STATE_IDLE
so in some case its fails to run your logic. Better if you check each and every callstate than you can get to know the problem.
You Have to exercise your brain little more..:)
check..It will help you
if (TelephonyManager.CALL_STATE_RINGING == state) {
Log.i(LOG_TAG, "RINGING start ");
isPhoneCalling = true;
AudioManager audioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setSpeakerphoneOn(true);
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
// active
Log.i(LOG_TAG, "OFFHOOK..callringing");
isPhoneCalling = true;
AudioManager audioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setSpeakerphoneOn(true);
}
if (TelephonyManager.CALL_STATE_IDLE == state) {
// run when class initial and phone call ended, need detect flag
// from CALL_STATE_OFFHOOK
Log.i(LOG_TAG, "_callend on start ");
Log.i("start ", "start "+callFromApp + isPhoneCalling );
if (isPhoneCalling) {
Log.i(LOG_TAG, "IDLE_callendafter ring ");
AudioManager audioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_NORMAL);
//Deactivate loudspeaker
audioManager.setSpeakerphoneOn(false);
// Remove listener
PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_NONE);
isPhoneCalling = false;
}
}