Get the media volume - Android Media

Android examples for Media:Media Volume

Description

Get the media volume

Demo Code


//package com.java2s;
import android.content.Context;
import android.media.AudioManager;

public class Main {
    private static AudioManager audio;

    /**//from   ww  w .j av  a 2 s . co m
     * Get the media volume
     * @param c Context
     * @return Volume
     */
    public static synchronized int getMediaVolume(Context c) {
        init(c);
        return audio.getStreamVolume(AudioManager.STREAM_MUSIC);
    }

    /**
     * Get the music manager
     * @param context
     */
    private static void init(Context context) {
        if (audio == null)
            audio = (AudioManager) context
                    .getSystemService(Context.AUDIO_SERVICE);
    }
}

Related Tutorials