AudioManager setMode - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for AudioManager setMode method.

This code example shows how to use the following methods:getRingerMode, setMode, setStreamVolume
      //retry player creation to pick up changed ringtones or audio server restarts 
      player = createPlayer();
    } 
 
    AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
    int ringerMode = audioManager.getRingerMode();
 
    if (shouldVibrate()) { 
      Log.i(TAG, "Starting vibration");
      vibrator.vibrate(VIBRATE_PATTERN, 1);
    } 
 
    if (player != null && ringerMode == AudioManager.RINGER_MODE_NORMAL ) {
      audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
      audioManager.setMode(AudioManager.MODE_RINGTONE);
      try { 
        if(!player.isPlaying()) {
          player.prepare();
          player.start();
          Log.d(TAG, "Playing ringtone now...");
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getRingerMode, requestAudioFocus, setMode
                .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 };

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isBluetoothScoAvailableOffCall, setMode, startBluetoothSco
			String message = null;
			try { 
				final AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
				BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter();
				if(ba != null && ba.isEnabled() && ba.getProfileConnectionState(BluetoothProfile.HEADSET) == BluetoothProfile.STATE_CONNECTED) {
					if(am.isBluetoothScoAvailableOffCall()) {
						registerReceiver(new BroadcastReceiver() {	
							@SuppressWarnings("serial") 
							@Override 
							public void onReceive(Context context, Intent intent) {
								if(intent.getExtras().getInt(AudioManager.EXTRA_SCO_AUDIO_STATE) == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
									context.unregisterReceiver(this);
									final TextToSpeech tts = new TextToSpeech(context, new OnInitListener() {									
										public void onInit(int status) {
											if(status != TextToSpeech.SUCCESS) {
												new AlertDialog.Builder(appContext).setTitle("Result").setMessage("Unable to Init").setNeutralButton("OK", null).show();
											} 
										} 
									}); 
									tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {	

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setMode
    private boolean mOriginalSpeakerStatus;
 
    @CalledByNative 
    public void setMode(int mode) {
        try { 
            mAudioManager.setMode(mode);
        } catch (SecurityException e) {
            Log.e(TAG, "setMode exception: " + e.getMessage());
            logDeviceInfo(); 
        } 
    } 
 
    @CalledByNative 
    private static AudioManagerAndroid createAudioManagerAndroid(Context context) {
        return new AudioManagerAndroid(context);
    } 
 
    private AudioManagerAndroid(Context context) {
        mContext = context;
        mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setMode, setSpeakerphoneOn
		audioManager.setSpeakerphoneOn(false);
	} 
	 
	public static void playThroughSpeaker(Activity activity) {
		AudioManager audioManager = getAudioManager(activity);
		audioManager.setMode(AudioManager.MODE_NORMAL); 
		audioManager.setSpeakerphoneOn(true);
	} 
 
	protected static AudioManager getAudioManager(Activity activity) {
		return (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
	} 
 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setBluetoothScoOn, setMode
		prepareBlueTooth(); 
	} 
 
	public void onClickEndMusic(View view) {
		player.stop();
		manager.setMode(AudioManager.MODE_NORMAL);
		manager.setBluetoothScoOn(false);
	} 
 
} 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setMode, setSpeakerphoneOn
		} 
	} 
 
	void beforePlay() { 
		playing = true;
		audioManager.setMode(AudioManager.MODE_IN_CALL);
		audioManager.setSpeakerphoneOn(true);
	} 
 
	void afterPlay() { 
		playing = false;
		audioManager.setMode(AudioManager.MODE_NORMAL);
		audioManager.setSpeakerphoneOn(false);
	} 
 
	public AudioManager getAudioManager() {
		return audioManager;
	} 
 
	public void setAudioManager(AudioManager audioManager) {
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isMusicActive, setMode
	} 
 
	public void resumeMusic() 
	{ 
		AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);    
		mAudioManager.setMode(AudioManager.MODE_NORMAL);
	    if (!mAudioManager.isMusicActive()) 
	    { 
		    Intent i = new Intent("com.android.music.musicservicecommand");	
		    i.putExtra("command", "next");
		    context.sendBroadcast(i);
	    }  
	} 
	 
	public void sayThis(String whatToSay)
	{ 
		tts.speak(whatToSay, TextToSpeech.QUEUE_ADD, soundSettings);	
	} 
	 
 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setMode, setSpeakerphoneOn
            // audio manager 
            player.setOnCompletionListener(new OnCompletionListener() {
 
                @Override 
                public void onCompletion(MediaPlayer mp) {
                    audioManager.setMode(AudioManager.MODE_IN_CALL);
                    audioManager.setSpeakerphoneOn(false);
                    stop(button);
                } 
 
            }); 
 
            // Set the volume of played media to maximum. 
            audioManager.setMode(AudioManager.MODE_NORMAL);
            audioManager.setStreamVolume(stream,
                    audioManager.getStreamMaxVolume(stream),
                    AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
            audioManager.setSpeakerphoneOn(true);
 
            player.setAudioStreamType(stream);
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setMode
	    ClipData clip = android.content.ClipData.newPlainText("Message", msg);
	    clipboard.setPrimaryClip(clip);
	} 
 
	public static void setAudioManagerInCallMode(AudioManager manager) {
		manager.setMode(AudioManager.MODE_IN_COMMUNICATION);
	} 
} 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related AudioManager setMode Questions & Answers:

setMode Method Overview
Sets the audio mode.
See Code Examples for other Android AudioManager Methods: