一. 按钮音
int nNotifCationVol = 0;
try{
nNotifCationVol = Settings.System.getInt(getContentResolver(),Settings.System.SOUND_EFFECTS_ENABLED);
}catch(SettingNotFoundException e){
e.printStackTrace();
}
二. 系统音量
1. 取系统音量
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
int nMaxVol = am.getStreamMaxVolume(AudioManager.STREAM_SYSTEM);
int nCurVol = am.getStreamVolume(AudioManager.STREAM_SYSTEM);
2. 设置系统音量
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
am.setStreamVolume(AudioManager.STREAM_SYSTEM, nVolume, 0);
注意:设置系统音量时要先设置权限,否则程序会崩溃,即在AndroidManifest.xml中添加一句<uses-permission android:name="android.permission.WRITE_SETTINGS" />如下所示:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="www.llxxhm.com"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".main"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="serve" ></activity>
<activity android:name="travel" ></activity>
<activity android:name="setting" ></activity>
<activity android:name="volume" ></activity>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
改通话音量只要把AudioManager.STREAM_SYSTEM改为AudioManager.STREAM_VOICE_CALL就行了