Code example for TelephonyManager

Methods: getCallState

     * Sets the Volume level in sensible range. Handles special case of someone is calling or if on call. 
     * @param context 
    private void setReasonableVolume(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        int callState = tm.getCallState();
        if (callState == TelephonyManager.CALL_STATE_OFFHOOK) {
            Log.v(TAG, "Customer on the phone, let's change volume");
            player.setVolume(VOLUME_OFF, VOLUME_OFF);
        } else if (callState == TelephonyManager.CALL_STATE_RINGING) {
            Log.v(TAG, "Someone is calling! Let's decrease volume.");
            player.setVolume(RINGING_VOLUME, RINGING_VOLUME);
        } else { 
            player.setVolume(1f, 1f);
Stop searching for code, let great code find you!  Add Codota to your java IDE