A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://sudarmuthu.com/blog/adjusting-the-volume-in-android-through-code below:

Adjusting the volume in Android through code

Adjusting the volume in Android through code

Published Mar 9, 2011 | In Android/Java

For my iAndroidRemote project, I had to adjust the volume of my Android phone. I found the code after digging around a bit.

I thought of sharing the code here, so that it would be useful for others and also I would know where to look for it when I need it for the next time.

Changing the volume in Android is pretty easy. You just need to know which class and method to call.

Getting the AudioManager Instance

First you have to get an instance of the AudioManager. You can get it by calling the getSystemService method of the Context object. If you are inside an Activity, you can get the instance by making the following code

Once you have the AudioManager instance, all you have to do is to call the adjustVolume method with appropriate arguments.

Increase Volume

To increase the volume you have to pass the AudioManager.ADJUST_RAISE constant.

Reduce Volume

And to reduce the volume you have to pass the AudioManager.ADJUST_LOWER constant.

I have created a small sample project to show the entire flow in action. You can download the project from my Github page.

Related posts

Tags: Android/Java, Volume


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4