List of usage examples for android.media AudioManager generateAudioSessionId
public int generateAudioSessionId()
From source file:io.github.carlorodriguez.morningritual.MainActivity.java
private void notifyStepFinish() { if (vibrateWhenStepFinish()) { ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(500); }/* w w w . ja v a 2s .c o m*/ if (soundWhenStepFinish()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { AudioAttributes audioAttributes = new AudioAttributes.Builder() .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setUsage(AudioAttributes.USAGE_NOTIFICATION).build(); AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); MediaPlayer.create(this, R.raw.sound, audioAttributes, audioManager.generateAudioSessionId()) .start(); } else { try { playLegacyNotificationSound(); } catch (IOException e) { Toast.makeText(MainActivity.this, R.string.cannot_load_notification_sound, Toast.LENGTH_SHORT) .show(); } } } }