Showing posts with label AudioManager. Show all posts
Showing posts with label AudioManager. Show all posts

getRingerMode - Get the Current Ringtone Mode (Normal, Silent, Vibrate)

getRingerMode was added in API Level 1
Returns: The current ringtone mode, one of RINGER_MODE_NORMAL, RINGER_MODE_SILENT, or RINGER_MODE_VIBRATE.

1. Initialize an AudioManager Variable named myAudioManager.

2. Set an integer variable named myInteger to mAudioManager.getRingerMode. This will save the ringer mode to a variable named myInteger.

3. In the MainActivity.java file, add the following code the onCreate method. 

if (myInteger == AudioManager.RINGER_MODE_NORMAL) {
    // add a toast that displays "Ringer is set to normal"

} else { (if (myInteger == AudioManager.RINGER_MODE_SILENT) {
        // add a toast that displays "Ringer is set to Silient"
    } else {

        if (myInteger == AudioManager.RINGER_MODE_VIBRATE) {
             // add a toast that displays "Ringer is set to Vibrate"
        }

3. Compile and run!

Next Recommended Article: Set Ringer to Vibrate

Resources:
http://developer.android.com/reference/android/media/AudioManager.html#getRingerMode()

Set Ringer to Vibrate

RINGER_MODE_VIBRATE was added in API Level 1
Ringer mode will be silent and will vibrate. (This will cause the phone ringer to always vibrate, but the notification vibrate to only vibrate if set.)

1. Initialize an AudioManager Variable named myAudioManager.

2. In the MainActivity.java file, add the following code the onCreate method. This will set the ringer to silent.

myAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);

3. Compile and run!

Next Recommended Article: Set Ringer to Silent

Resources:
http://developer.android.com/reference/android/media/AudioManager.html#RINGER_MODE_VIBRATE

A fun Android Vibrating png
http://img.cryptlife.com/2012/08/android_custom_vibrations_create_cryptlife.png

Set Ringer to Silent

RINGER_MODE_SILENT was added in API Level 1
Ringer mode that will be silent and will not vibrate. (This overrides the vibrate setting.)

1. Initialize an AudioManager Variable named myAudioManager.

2. In the MainActivity.java file, add the following code the onCreate method. This will set the ringer to silent.

myAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);

3. Compile and run!

Next Recommended Article: Set Ringer to Normal

Resources:
http://developer.android.com/reference/android/media/AudioManager.html#RINGER_MODE_SILENT

Initialize an AudioManager Variable

AUDIO_SERVICE was added in API Level 1
AUDIO_SERVICE: Use with getSystemService(String) to retrieve a AudioManager for handling management of volume, ringer modes and audio routing.

1. Create an AudioManager variable named myAudioManager.

2. In the MainActivity.java file, add the following line. This will get an instance of this class.

myAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE);

3. Compile and run!

Next Recommended Article: Get the Current Ringtone Mode (Normal, Silent, Vibrate)

Resources:
http://developer.android.com/reference/android/content/Context.html#AUDIO_SERVICE

Create an AudioManager Variable

AudioManager was added in API Level 1
AudioManager provides access to volume and ringer mode control.

1. Create an Android project, if you don't already have one.

2. In the MainActivity.java file in the imports section add the following code.

import android.media.AudioManager;

3. In the onCreate method, add the following line. This will create an AudioManager variable named myAudiomanager.

AudioManager myAudioManager;

3. Compile and run!

Next Recommended Article: Initialize an AudioManager Variable

Resources:
http://developer.android.com/reference/android/media/AudioManager.html