Disable toast toast

I am trying to increase the volume using AudioManager.

But it shows that the user interface for Android (Volume Seekbar) toast.I want to disable this. I know that this is possible in Activity using Key Event, but I want to do this through a service. How to disable toast? Here is a screenshot of the toast:
enter image description here

+5
source share
2 answers

The class AudioManageroffers the following ways to adjust the volume of certain threads:

All of these methods accept the flag-parameter as the last argument. The flag that interests you is FLAG_SHOW_UIthat:

Show the toast containing the current volume.

, Toast, , ( int 1), ( ) 0:

AudioManager manager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
manager.adjustVolume(AudioManager.ADJUST_RAISE, 0);

Android 4.0.4 (Motorola Xoom) Android 2.3.5 (HTC Desire HD).

+7

, , , :

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch(keyCode) {
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            //volumeDown();
            return true;
        case KeyEvent.KEYCODE_VOLUME_UP:
            //volumeUp();
            return true;
    }
    return super.onKeyUp(keyCode, event);
}


@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch(keyCode) {
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            volumeDown();
            return true;
        case KeyEvent.KEYCODE_VOLUME_UP:
            volumeUp();
            return true;
    }
    return super.onKeyDown(keyCode, event);
}

private void volumeUp(){
    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, SOME_RANDOM_VALUE, AudioManager.FLAG_VIBRATE);
}

onKeyUp onKeyDown ( ).

- , Android .

+3

All Articles