熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> 移動開發 >> 正文

Android開發中如何獲取鈴聲和音量

2022-06-13   來源: 移動開發 

通過程序獲取android系統手機的鈴聲和音量設置音量的方法也很簡單AudioManager提供了方法
publicvoidsetStreamVolume(intstreamTypeintindexintflags)其中streamType有內置的常量去文檔裡面就可以看到  Java代碼
AudioManager mAudioManager = (AudioManager) getSystemService(ContextAUDIO_SERVICE);
//通話音量
int max = mAudioManagergetStreamMaxVolume( AudioManagerSTREAM_VOICE_CALL );
int current = mAudioManagergetStreamVolume( AudioManagerSTREAM_VOICE_CALL );
Logd(VIOCE_CALL max : + max + current : + current);
//系統音量
max = mAudioManagergetStreamMaxVolume( AudioManagerSTREAM_SYSTEM );
current = mAudioManagergetStreamVolume( AudioManagerSTREAM_SYSTEM );
Logd(SYSTEM max : + max + current : + current);
//鈴聲音量
max = mAudioManagergetStreamMaxVolume( AudioManagerSTREAM_RING );
current = mAudioManagergetStreamVolume( AudioManagerSTREAM_RING );
Logd(RING max : + max + current : + current);
//音樂音量
max = mAudioManagergetStreamMaxVolume( AudioManagerSTREAM_MUSIC );
current = mAudioManagergetStreamVolume( AudioManagerSTREAM_MUSIC );
Logd(MUSIC max : + max + current : + current);
//提示聲音音量
max = mAudioManagergetStreamMaxVolume( AudioManagerSTREAM_ALARM );
current = mAudioManagergetStreamVolume( AudioManagerSTREAM_ALARM );
Logd(ALARM max : + max + current : + current);


From:http://tw.wingwit.com/Article/program/yd/201404/30430.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.