Answer the question
In order to leave comments, you need to log in
How to make it so that when the screen of the android simulator is rotated, a sound is made?
The task is such that when the android simulator changes position from Portrait to Landscape Mode, sound should be produced. There are no questions with sounds, I have sounds, I turned them on through MediaPlayer. I already wrote android:configChanges = "orientation | screenSize" in the manifest, but it's not clear how to write code in MainActivity.java. Can someone help?
Answer the question
In order to leave comments, you need to log in
something like this
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
play_sound();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
play_sound();
}
}
private void play_sound()
{
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question