Android 获取系统音量

关于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:标志位,不太清楚做什么的。

你可能感兴趣的:(Android,开发之路,笔记)