-3

I'm looking to make a simple volume manager app. I know it has been done before but I am just looking to make one to see what its like and to get more familiar with the code and doing certain things with it.

I'm hoping that it could include an if statement where if the volume drops below zero it makes a "Toast" notification saying something along the lines of "You have dropped below zero"

As much as it sounds like I am asking for someone to do this for me I am just asking for a basic idea / framework to work with.

-Thanks for the help!

a.kollar
  • 43
  • 6
  • How about reading the documentation? http://developer.android.com/guide/topics/ui/notifiers/toasts.html – Graham Borland Jul 05 '12 at 15:45
  • @Graham Thanks for that. I should have looked there first. Been working on learning for the last two weeks and I should have known. Again thanks for the tip. – a.kollar Jul 05 '12 at 15:50

1 Answers1

0

I assume you wanted more information than just how to make a Toast. So here are few other pointers.

To access the volume level use AudioManager:

AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int currentVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC);

Catching the volume buttons is simple enough:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    super.onKeyUp(keyCode, event);
    if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
        // Do something if currentVolume is low enough
        // return true;
    }
    // Check if Up is pushed too
    return false;
}

And a Toast is pretty easy too:

Toast.makeText(context, "Message", Toast.LENGTH_LONG).show();

If you ever want your app / service to do more with the current volume, you may realize that this isn't as straight forward as it sounds...

This method tells the system which audio stream to adjust with the volume buttons while your app is active:

setVolumeControlStream(AudioManager.STREAM_MUSIC);

Read the documentation on this and you get a glimpse of how unpredictable tracking the volume yourself can be. Here's a question on the same subject: How can I manage audio volumes sanely in my Android app?

Community
  • 1
  • 1
Sam
  • 86,580
  • 20
  • 181
  • 179