![]() |
VOOZH | about |
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_NORMAL | This mode will set your device mode to Normal/General mode. |
|---|---|
| RINGER_MODE_SILENT | This mode will set your device mode to Silent mode. |
| RINGER_MODE_VIBRATE | This mode will set your device mode to vibrate mode. |
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 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.
Project Link:Click Here