get Voice Current Percent - Android Media

Android examples for Media:Audio

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 ww  .j  ava 2  s  .c o  m*/
}

Related Tutorials