You should be familiar with setting the scene mode. However, in Android, how can you set the scene mode through your own program? There are many kinds of scenes, that is, you can use the built-in system, you can also use custom mode. However, when developing some programs, you may need to change the context mode in the program. Therefore, you need to set the context mode. The following describes how to set the situation mode:
First, obtain the current scene mode:
Code
Copy codeThe Code is as follows: void getInitring (AudioManager audio)
{
// Obtain the initial volume of the phone and initialize the progress bar
Int volume = audio. getStreamVolume (AudioManager. STREAM_RING); // obtain the initial volume.
// Get the initial mode and set the icons respectively
Int mode = audio. getRingerMode (); // get the initial mode
}
Through this code, of course, you need to process it again, so that you can get the current scene mode, prepare for future settings, and then you may know whether to set it again.
Set scene mode 1: sound, no vibration:
CodeCopy codeThe Code is as follows: void ring (AudioManager audio ){
Audio. setRingerMode (AudioManager. RINGER_MODE_NORMAL );
Audio. setVibrateSetting (AudioManager. VIBRATE_TYPE_RINGER,
AudioManager. VIBRATE_SETTING_OFF );
Audio. setVibrateSetting (AudioManager. VIBRATE_TYPE_NOTIFICATION,
AudioManager. VIBRATE_SETTING_OFF );
Toast. makeText (this, "set successfully! The current ringtone is ", Toast. LENGTH_LONG). show ();
}
After setting, the system only has sound and no vibration.
Set scene mode 2: either sound or vibration:
CodeCopy codeThe Code is as follows: void ringAndVibrate (AudioManager audio ){
Audio. setRingerMode (AudioManager. RINGER_MODE_NORMAL );
Audio. setVibrateSetting (AudioManager. VIBRATE_TYPE_RINGER,
AudioManager. VIBRATE_SETTING_ON );
Audio. setVibrateSetting (AudioManager. VIBRATE_TYPE_NOTIFICATION,
AudioManager. VIBRATE_SETTING_ON );
Toast. makeText (this, "set successfully! Add vibration to the ringtone currently ", Toast. LENGTH_LONG). show ();
}
After this setting, there will also be a vibration reminder when the voice is voiced.
Set scene mode 3: Vibration only:
CodeCopy codeThe Code is as follows: void vibrate (AudioManager audio ){
Audio. setRingerMode (AudioManager. RINGER_MODE_VIBRATE );
Audio. setVibrateSetting (AudioManager. VIBRATE_TYPE_RINGER,
AudioManager. VIBRATE_SETTING_ON );
Audio. setVibrateSetting (AudioManager. VIBRATE_TYPE_NOTIFICATION,
AudioManager. VIBRATE_SETTING_ON );
Toast. makeText (this, "set successfully! Current vibration ", Toast. LENGTH_LONG). show ();
}
After this setting, There is only vibration and no sound:
Set scene mode 4: silent and non-vibration:
CodeCopy codeThe Code is as follows: void noRingAndVibrate (AudioManager audio ){
Audio. setRingerMode (AudioManager. RINGER_MODE_SILENT );
Audio. setVibrateSetting (AudioManager. VIBRATE_TYPE_RINGER,
AudioManager. VIBRATE_SETTING_OFF );
Audio. setVibrateSetting (AudioManager. VIBRATE_TYPE_NOTIFICATION,
AudioManager. VIBRATE_SETTING_OFF );
Toast. makeText (this, "set successfully! Currently it is silent without vibration ", Toast. LENGTH_LONG). show ();
}
After the settings, the system does not have sound or vibration. The error message is not displayed.
The voice of all the above settings is the default sound size of the system. Can we customize the sound size? The answer is yes of course. To set the sound size, you need to set the following function:
Increase volume:Copy codeThe Code is as follows: audio. adjustVolume (AudioManager. ADJUST_RAISE, 0 );
Decrease volume:Copy codeThe Code is as follows: audio. adjustVolume (AudioManager. ADJUST_LOWER, 0 );
The above is the most basic setting method. Many of the more complex combinations in use are formed by the combination of the basic methods.