Android adjusts the volume-Application of audiomanager

Source: Internet
Author: User

In Android, you can use a program to get the ringtones and volume of the system's mobile phone. You can also set the ringtone and volume. Android provides the audiomanager class for volume acquisition and volume control.

This article is based on the audiomanager In the android API and provides an example.

The following is an outline of this article:

  • 1. Learn about audiomanager
  • 2. Introduction to audiomanager
  • 3. Parameter explanation

1. Learn about audiomanager

The audiomanager class is located in the Android. Media package, which provides operations to control the volume and audible mode.

2. Introduction to audiomanager

There are too many methods for mail to audiomanager. Here are only a few common methods:

  • Method: adjuststreamvolume (INT streamtype, int direction, int flags)
    Streamtype is the ringtone type, for example, audiomanager. stream_voice_call, audiomanager. stream_system, direction. When the first parameter is audiomanager. when adjust_lower is used, you can reduce the volume by one unit and transfer it to audiomanager. when adjust_raise is used, you can increase the volume by one unit. Flags is the flag.
  • Method: getmode ()
    Explanation: The current audio mode is returned. For example:MODE_NORMAL,MODE_RINGTONE,MODE_IN_CALLOrMODE_IN_COMMUNICATION
  • Method: getringermode ()
    Explanation: The current ringtone mode is returned. For exampleRINGER_MODE_NORMAL,RINGER_MODE_SILENT, OrRINGER_MODE_VIBRATE.
  • Method: getstreamvolume (INT streamtype)
    Explanation: Obtain the current mobile phone volume. The maximum value is 7 and the minimum value is 0. When the value is 0, the mobile phone automatically adjusts the mode to "vibrate ".
  • Method: setstreamvolume (INT streamtype, int index, int flags)
    Explanation: changes the ringtone volume. The explanation is the same as 1. The index indicates the sound size.
  • Method: setmode (INT Mode)
    Explanation: Change the audio mode. See the get method.
  • Method: setringermode (INT ringermode)
    Explanation: Change the ringtone mode. See the get method.

3. Parameter explanation

Streamtype:

  1. Stream_alarm alert
  2. Stream_music music playback is the media volume.
  3. Stream_notification notification,
  4. Stream_ring ringtones
  5. Stream_system
  6. Stream_voice_call
  7. Stream_dtmf dual-Tone Multi-frequency, dial-up key sound
    Direction is the direction of adjustment. It can be:
  1. Adjust_lower volume reduction
  2. Adjust_raise increases the volume
  3. Adjust_same remains unchanged, which is mainly used to show the current volume to the user
    Flags, which is an additional parameter:

  1. Flag_play_sound
  2. When flag_show_ui is adjusted, the volume bar is displayed, which is the page displayed by the volume key.
  3. Flag_remove_sound_and_vibrate without vibration or sound
  4. Flag_allow_ringer_modes whether to include ringer modes as possible options when changing volume.
  5. Flag_vibrate whether to vibrate if going into the vibrate ringer Mode

**************************************** *******************************

* Reprint must be noted in the obvious: http://blog.csdn.net/xyz_lmn *

* Author: Zhang xingye *

* Mailbox: xy-zhang@163.com *

**************************************** *******************************

Reference: callback /**
* @ Author Zhang xingye
* Email: xy-Zhang # 163.com
* Android Development Group: 278401545
*
*/

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.