Everyone should be quite familiar with the setting of scenario mode, but in Android, how to set the scenario mode through your own program? Scenario modes are divided into many types, that is, you can use the system-owned or customized ones. However, when developing some programs, you may need to change the scenario mode in the program, so you need to set the scenario mode. The following is a brief introduction to the setting of the situation mode:
First get the current scenario mode:
Code
void getInitring(AudioManager audio)
{
//Get the initial volume of the phone and initialize the progress bar
int volume=(AudioManager.STREAM_RING); //Get initial volume
//Get the initial mode and set the icons separately
int mode=(); //Get initial mode
}
Through this code, of course, you need to process it again, so you can get the current scenario mode, prepare for future settings, and then you may also know whether to set it again.
Set Scenario Mode 1: Only sound, no vibration:
Code
void ring(AudioManager audio) {
(AudioManager.RINGER_MODE_NORMAL);
(AudioManager.VIBRATE_TYPE_RINGER,
AudioManager.VIBRATE_SETTING_OFF);
(AudioManager.VIBRATE_TYPE_NOTIFICATION,
AudioManager.VIBRATE_SETTING_OFF);
(this, "Set successfully! Currently ringtone", Toast.LENGTH_LONG).show();
}
After setting, the system only has sound and no vibration.
Set Scenario Mode 2: There is sound and vibration:
Code
void ringAndVibrate(AudioManager audio) {
(AudioManager.RINGER_MODE_NORMAL);
(AudioManager.VIBRATE_TYPE_RINGER,
AudioManager.VIBRATE_SETTING_ON);
(AudioManager.VIBRATE_TYPE_NOTIFICATION,
AudioManager.VIBRATE_SETTING_ON);
(this, "Setting successful! Vibration is currently added to the ringtone", Toast.LENGTH_LONG).show();
}
After setting this way, there will also be a vibration reminder when making sounds.
Set Scenario Mode Three: Only Vibrate:
Code
void vibrate(AudioManager audio) {
(AudioManager.RINGER_MODE_VIBRATE);
(AudioManager.VIBRATE_TYPE_RINGER,
AudioManager.VIBRATE_SETTING_ON);
(AudioManager.VIBRATE_TYPE_NOTIFICATION,
AudioManager.VIBRATE_SETTING_ON);
(this, "Set successfully! Currently vibrating", Toast.LENGTH_LONG).show();
}
After this setting, there is only vibration and no sound:
Set Scenario Mode 4: Silent and No vibration:
Code
void noRingAndVibrate(AudioManager audio) {
(AudioManager.RINGER_MODE_SILENT);
(AudioManager.VIBRATE_TYPE_RINGER,
AudioManager.VIBRATE_SETTING_OFF);
(AudioManager.VIBRATE_TYPE_NOTIFICATION,
AudioManager.VIBRATE_SETTING_OFF);
(this, "Set successfully! Currently silent and vibration-free", Toast.LENGTH_LONG).show();
}
The system has no sound or vibration after setting. The corresponding prompt cannot be made.
All the sounds set above are the default sound size of the system. So can we customize the sound size? The answer is of course possible. To set the sound size, you need to set the following function:
Increase the volume:
(AudioManager.ADJUST_RAISE, 0);
Reduce the volume:
(AudioManager.ADJUST_LOWER, 0);
The above is the most basic setting method, and many more complex combinations are made up of this basic method in use.
First get the current scenario mode:
Code
Copy the codeThe code is as follows:
void getInitring(AudioManager audio)
{
//Get the initial volume of the phone and initialize the progress bar
int volume=(AudioManager.STREAM_RING); //Get initial volume
//Get the initial mode and set the icons separately
int mode=(); //Get initial mode
}
Through this code, of course, you need to process it again, so you can get the current scenario mode, prepare for future settings, and then you may also know whether to set it again.
Set Scenario Mode 1: Only sound, no vibration:
Code
Copy the codeThe code is as follows:
void ring(AudioManager audio) {
(AudioManager.RINGER_MODE_NORMAL);
(AudioManager.VIBRATE_TYPE_RINGER,
AudioManager.VIBRATE_SETTING_OFF);
(AudioManager.VIBRATE_TYPE_NOTIFICATION,
AudioManager.VIBRATE_SETTING_OFF);
(this, "Set successfully! Currently ringtone", Toast.LENGTH_LONG).show();
}
After setting, the system only has sound and no vibration.
Set Scenario Mode 2: There is sound and vibration:
Code
Copy the codeThe code is as follows:
void ringAndVibrate(AudioManager audio) {
(AudioManager.RINGER_MODE_NORMAL);
(AudioManager.VIBRATE_TYPE_RINGER,
AudioManager.VIBRATE_SETTING_ON);
(AudioManager.VIBRATE_TYPE_NOTIFICATION,
AudioManager.VIBRATE_SETTING_ON);
(this, "Setting successful! Vibration is currently added to the ringtone", Toast.LENGTH_LONG).show();
}
After setting this way, there will also be a vibration reminder when making sounds.
Set Scenario Mode Three: Only Vibrate:
Code
Copy the codeThe code is as follows:
void vibrate(AudioManager audio) {
(AudioManager.RINGER_MODE_VIBRATE);
(AudioManager.VIBRATE_TYPE_RINGER,
AudioManager.VIBRATE_SETTING_ON);
(AudioManager.VIBRATE_TYPE_NOTIFICATION,
AudioManager.VIBRATE_SETTING_ON);
(this, "Set successfully! Currently vibrating", Toast.LENGTH_LONG).show();
}
After this setting, there is only vibration and no sound:
Set Scenario Mode 4: Silent and No vibration:
Code
Copy the codeThe code is as follows:
void noRingAndVibrate(AudioManager audio) {
(AudioManager.RINGER_MODE_SILENT);
(AudioManager.VIBRATE_TYPE_RINGER,
AudioManager.VIBRATE_SETTING_OFF);
(AudioManager.VIBRATE_TYPE_NOTIFICATION,
AudioManager.VIBRATE_SETTING_OFF);
(this, "Set successfully! Currently silent and vibration-free", Toast.LENGTH_LONG).show();
}
The system has no sound or vibration after setting. The corresponding prompt cannot be made.
All the sounds set above are the default sound size of the system. So can we customize the sound size? The answer is of course possible. To set the sound size, you need to set the following function:
Increase the volume:
Copy the codeThe code is as follows:
(AudioManager.ADJUST_RAISE, 0);
Reduce the volume:
Copy the codeThe code is as follows:
(AudioManager.ADJUST_LOWER, 0);
The above is the most basic setting method, and many more complex combinations are made up of this basic method in use.