Android 获取系统音量

非原创,转载:http://blog.csdn.net/h623691640/article/details/51492255
关于Android获取系统音量值的文章在网上随便一搜就一大堆,我在此再整理只是为了更方便与学习,相当于做笔记吧。

                AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

                max = am.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL);// 0
                current= am.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
                Log.e("service", "通话音量值:" + max + "-" + current);

                max = am.getStreamMaxVolume(AudioManager.STREAM_SYSTEM);// 1
                current = am.getStreamVolume(AudioManager.STREAM_SYSTEM);
                Log.e("service", "系统音量值:" + max + "-" + current);

                max = am.getStreamMaxVolume(AudioManager.STREAM_RING);// 2
                current = am.getStreamVolume(AudioManager.STREAM_RING);
                Log.e("service", "系统铃声值:" + max + "-" + current);

                max = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);// 3
                current = am.getStreamVolume(AudioManager.STREAM_MUSIC);
                Log.e("service", "音乐音量值:" + max + "-" + current);

                max = am.getStreamMaxVolume(AudioManager.STREAM_ALARM);// 4
                current = am.getStreamVolume(AudioManager.STREAM_ALARM);
                Log.e("service", "闹铃音量值:" + max + "-" + current);

                max = am.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION);// 5
                current = am
                        .getStreamVolume(AudioManager.STREAM_NOTIFICATION);
                Log.e("service", "提示声音音量值:" + max + "-" + current);

                // ------还可以通过动态设置音量值的大小,方法如下:
                // public void setStreamVolume(int streamType, int index,
                // int flags);
                // streamType以上几种模式中的一种,
                // index:设置音量的大小
                // flags:标志位,不太清楚做什么的。
    原文作者:小小程序员jh
    原文地址: https://www.jianshu.com/p/5cfbc9e1c13c
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞