解决方法
您可以使用AudioManager检查音量是静音还是静音.
AudioManager audio = (AudioManager) context.getSystemService(Context.AUdio_SERVICE); switch( audio.getRingerMode() ){ case AudioManager.RINGER_MODE_NORMAL: break; case AudioManager.RINGER_MODE_SILENT: break; case AudioManager.RINGER_MODE_VIBRATE: break; }
对于Volume更改,有BroadcastReceiver.
public class VolumeKeyReceiver extends BroadcastReceiver { @Override public void onReceive(Context context,Intent intent) { //Implement Logic } }
注册BroadcastReceiver
VolumeKeyReceiver keyReceiver = new VolumeKeyReceiver(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("android.media.VOLUME_CHANGED_ACTION"); registerReceiver(keyReceiver,intentFilter);