Code example for AudioManager

Methods: getRingerModerequestAudioFocussetMode

0
                .getSystemService(Context.AUDIO_SERVICE);
    } 
 
    private synchronized void ringIncoming() { 
        Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
        int ringerMode = mAudioManager.getRingerMode();
        mVibrator = (Vibrator) mContext
                .getSystemService(Context.VIBRATOR_SERVICE);
        if (mCallInProgress) {
            // Notify with single vibrate. 
            mVibrator.vibrate((long) 200);
        } else { 
            if (AudioManager.RINGER_MODE_NORMAL == ringerMode) {
                mAudioManager.setMode(AudioManager.MODE_RINGTONE);
                ring(uri, AudioManager.STREAM_RING);
            } else if (AudioManager.RINGER_MODE_VIBRATE == ringerMode) {
 
                // Start immediately 
                // Vibrate 400, break 200, Vibrate 400, break 1000 
                long[] pattern = { 0, 400, 200, 400, 1000 };
 
                // Vibrate until cancelled. 
                mVibrator.vibrate(pattern, 0);
            } // else RINGER_MODE_SILENT 
        } 
    } 
 
    private synchronized void ring(Uri uri, int streamType) {
        mAudioManager.requestAudioFocus(null, streamType,
                AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
        try { 
            if (mRingerPlayer != null) {
                mRingerPlayer.stop();
            }