Question

I've read here. Didn't find the answer.

public class CallReceiver extends BroadcastReceiver {

private TelephonyManager mTelephony;
private IncomingPhoneStateListener mIncomingPhoneListener;
private String number;
private Context mContext;

@Override
public void onReceive(Context context, Intent intent) {
    try {
        mContext = context;
        number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
        mTelephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        mIncomingPhoneListener = new IncomingPhoneStateListener();
        mTelephony.listen(mIncomingPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
    } catch (Exception e) {
        Log.e("CallReceiver", "onReceive error:" + e.getMessage());
    }
}

public class IncomingPhoneStateListener extends PhoneStateListener {
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {

        AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);

        switch (state) {
            case TelephonyManager.CALL_STATE_RINGING:

                // ******* This code should unmute and change volume to MAX
                am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                am.setStreamVolume(AudioManager.STREAM_RING, am.getStreamMaxVolume(AudioManager.STREAM_RING), AudioManager.FLAG_PLAY_SOUND);
                // ******* end
                break;
            case TelephonyManager.CALL_STATE_OFFHOOK:
                break;
            case TelephonyManager.CALL_STATE_IDLE:
                break;
            default:
                break;
        }
        super.onCallStateChanged(state, incomingNumber);
        mTelephony.listen(mIncomingPhoneListener, PhoneStateListener.LISTEN_NONE); // unregister
    }
}

}

When the device is on silent mode or vibration mode, above code unmute and change the volume to the max. This code works on Nexus devices (eg. Galaxy Nexus) However, it doesn't work on Samsung devices (S3, S4, Note 2) [Android version 4.3].

Any suggestions?

Was it helpful?

Solution

Since I couldn't find the answer, I came up with the work-around by actually playing the ringer sound in my service.

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