Set the android scene mode

Source: Internet
Author: User

You should be familiar with setting the scene mode, but how to use your ownProgramYou can set the scenario mode in multiple ways, that is, you can use the built-in or custom scenarios, but when developing some programs, you may need to change the context mode in the program. The following describes how to set the situation mode:

First, obtain the current scene mode:

 

Code

  Void  Getinitring (audiomanager audio)
{
// Get the initial volume of the phone and initialize the progress bar
Int Volume = Audio. getstreamvolume (audiomanager. stream_ring ); // Get initial volume
// Get the initial mode and set the icons respectively
Int Mode = Audio. getringermode (); // Get initial Mode
}

 

Use thisCodeOf course, you need to process it again so that you can get the current scene mode, prepare for future settings, and you may know whether to set it again.

 

Set scene mode 1: sound, no vibration:

Code

  VoidRing (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! Currently, it is a ringtone.", Toast. length_long). Show ();
}

 

After setting, the system only has sound and no vibration.

Set scene mode 2: either sound or vibration:

Code

  VoidRingandvibrate (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! Currently, the ringtone and vibration are added.", 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:

Code

  VoidVibrate (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 as Vibration", Toast. length_long). Show ();
}

 

After this setting, There is only vibration and no sound:

Set scene mode 4: silent and non-vibration:

Code

  VoidNoringandvibrate (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 and non-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:

 
  Audio. adjustvolume (audiomanager. adjust_raise,0);

 

Decrease volume:

 
  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.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.