Question

My application Call_withSpeaker on setting alarm is working fine in android 4.2.1 micromax , 4.1.2 samsung and 2.3 motorala. Only Problem with Samsung 4.2.2.. every thing fine but the speaker is not enable on call start only in 4.2.2 samsung . I am Using PhoneStateListener and if call start once i use

AudioManager audioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
                  audioManager.setMode(AudioManager.MODE_IN_CALL);
                  audioManager.setSpeakerphoneOn(true);  

The issue what i am facing here is Turn Speaker Phone on and off is not working properly only for Samsung 4.2.2 and samsung duas 4.1.2 What to do.. Any idea ?? Is it related to version or some setting in mobile ... ?? Thank you ..

Was it helpful?

Solution

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;


           }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top