How do I change the BlackBerry volume or mute the sound?
My current code:
int volume = Alert.getVolume(); // reads 100
Alert.setVolume(0);
It does not change the volume setting as it should. Even a call Alert.mute(true);
does not have any good effect.
Audio.setVolume(0);
doesn't work either!
I am running this on Curve 8310. I have another piece of software that successfully manages to lower the volume significantly. I suppose I am doing something wrong. Any idea?
source to share
If you want to play sound using Alert :
class Scr extends MainScreen implements FieldChangeListener {
ButtonField mVolumeUp;
ButtonField mVolumeDown;
ButtonField mPlay;
LabelField mVolumeLabel;
int mVolumeValue = 50;
private static final short[] tune = new short[] { 466, 125, 10, 466 };
public Scr() {
mVolumeLabel = new LabelField("Volume: " + mVolumeValue);
add(mVolumeLabel);
mVolumeUp = new ButtonField("Vol Up", ButtonField.CONSUME_CLICK);
mVolumeUp.setChangeListener(this);
add(mVolumeUp);
mVolumeDown = new ButtonField("Vol Down", ButtonField.CONSUME_CLICK);
mVolumeDown.setChangeListener(this);
add(mVolumeDown);
mPlay = new ButtonField("Play", ButtonField.CONSUME_CLICK);
mPlay.setChangeListener(this);
add(mPlay);
}
public void fieldChanged(Field field, int context) {
if (mVolumeUp == field) {
if (mVolumeValue <= 90)
mVolumeValue += 10;
mVolumeLabel.setText("Volume: " + mVolumeValue);
} else if (mVolumeDown == field) {
if (mVolumeValue >= 10)
mVolumeValue -= 10;
mVolumeLabel.setText("Volume: " + mVolumeValue);
} else if (mPlay == field) {
Alert.startAudio(tune, mVolumeValue);
}
}
}
Tested on RIM 4.5 8310 Trainer
source to share
If you are using a class javax.microedition.lcdui.Alert
this might be your problem. Try looking at the class net.rim.device.api.notification.NotificationsManager
and other package classes / interfaces.
An easy / polite way though is to just ask the user to manually change user profiles. If I set my blackberry to silence and some application makes a crazy noise (or no noise at all if I'm expecting an important call), I will uninstall that application as soon as possible.