VOOZH about

URL: https://www.geeksforgeeks.org/android/audiomanager-in-android-with-example/

⇱ AudioManager in Android with Example - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

AudioManager in Android with Example

Last Updated : 23 Jul, 2025

AudioManager is a class provided by Android which can be used to control the ringer volume of your Android device. With the help of this Audio Manager class, you can easily control the ringer volume of your device. Audio Manager Class can be used by calling the getSystemService() method in Android. When you create Audio Manager Class then you can use setRingerMode() method to change the ringer volume of your device. The setRingerMode() method takes an integer parameter to set the ringer profile of your device. There are three different integer parameters that need to be passed in setRingerMode() method are as follows: 

RINGER_MODE_NORMALThis mode will set your device mode to Normal/General mode.
RINGER_MODE_SILENTThis mode will set your device mode to Silent mode.
RINGER_MODE_VIBRATEThis mode will set your device mode to vibrate mode. 

Example

This is a Simple Example where we are creating a Ringtone Manager App. This app will help you to change the current state of your device from General to Vibrate and then to Silent Mode. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language.

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Add permissions in the AndroidManifest.xml file

Add below line in AndroidManifest.xml file. 

<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />

Step 3: Add google repository in the build.gradle file of the application project if by default it is not there

buildscript {

 repositories {

    google()

    mavenCentral()

}

All Jetpack components are available in the Google Maven repository, include them in the build.gradle file

allprojects {

 repositories {

    google()

   mavenCentral()

 }

}

Step 4: Modify the strings.xml file

Below is the code for the strings.xml file.

Step 5: Working with the activity_main.xml file

Below is the code for the activity_main.xml file. Comments are added inside the code to understand the code in more detail.

Step 6: Working with the MainActivity.java file

Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.

Output: Run the app on your device


Project Link:Click Here

Comment

Explore