get Voice Current Percent - Android Phone

Android examples for Phone:Volume

Description

get Voice Current Percent

Demo Code


//package com.java2s;

import android.content.Context;

import android.media.AudioManager;

public class Main {
    public static int getVoiceCurrentPercent(Context context) {
        AudioManager mAudioManager = (AudioManager) context
                .getSystemService(Context.AUDIO_SERVICE);
        float max = (float) mAudioManager
                .getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        float current = (float) mAudioManager
                .getStreamVolume(AudioManager.STREAM_MUSIC);
        float percent = current / max * 100;

        return (int) percent;
    }/*from   w w  w . jav  a 2s. c  om*/
}

Related Tutorials