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:標誌位,不太清楚做什麼的。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章