How to Get and set the ringtones and volume of the android System

Source: Internet
Author: User

From: http://www.inandroid.cn/bbs/thread-132546-1-1.html

Obtain the ringtones and volume of the Android mobile phone through a program. Similarly, you can set the ringtone and volume easily!

The method for setting the volume is also very simple. audiomanager provides the method:

Publicvoidsetstreamvolume (intstreamtype, intindex, intflags) Where streamtype has built-in constants, which can be seen in the document.


Java code:

Audiomanager maudiomanager = (audiomanager) getsystemservice (context. audio_service );


// Call volume


Int max = maudiomanager. getstreammaxvolume (audiomanager. stream_voice_call );

Int current = maudiomanager. getstreamvolume (audiomanager. stream_voice_call );

Log. D ("vioce_call", "MAX:" + MAX + "current:" + current );


// System volume


Max = maudiomanager. getstreammaxvolume (audiomanager. stream_system );

Current = maudiomanager. getstreamvolume (audiomanager. stream_system );

Log. D ("system", "MAX:" + MAX + "current:" + current );


// Ringtone volume


Max = maudiomanager. getstreammaxvolume (audiomanager. stream_ring );

Current = maudiomanager. getstreamvolume (audiomanager. stream_ring );

Log. D ("Ring", "MAX:" + MAX + "current:" + current );


// Music volume


Max = maudiomanager. getstreammaxvolume (audiomanager. stream_music );

Current = maudiomanager. getstreamvolume (audiomanager. stream_music );

Log. D ("music", "MAX:" + MAX + "current:" + current );


// Sound volume prompt


Max = maudiomanager. getstreammaxvolume (audiomanager. stream_alarm );

Current = maudiomanager. getstreamvolume (audiomanager. stream_alarm );

Log. D ("alarm", "MAX:" + MAX + "current:" + current );

PS:

During the game, you can only adjust the multimedia volume, but not the call volume.

Setvolumecontrolstream (audiomanager. stream_music );

Black screen is not allowed because the screen remains unchanged for a long time. View. setkeepscreenon (true );

It is estimated that the permission must be registered in the manifest file.

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.