先生,即使铃声被静音,是否可以响铃?如果是,如何。而且,我可以将它的音量设置在两者之间,而不仅仅是 maxvolume 吗?提前致谢
for (SmsMessage msg : messages) {
if (msg.getMessageBody().contains("firealert")) {
Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
if(alert == null){
// alert is null, using backup
alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if(alert == null){
// alert backup is null, using 2nd backup
alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
}
}
Ringtone r = RingtoneManager.getRingtone(context.getApplicationContext(), alert);
AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
int maxVolumeAlarm = audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
int maxVolumeRing = audioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, maxVolumeAlarm,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
audioManager.setStreamVolume(AudioManager.STREAM_RING, maxVolumeRing,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
r.play();
Toast.makeText(context.getApplicationContext(), "alarm started", Toast.LENGTH_LONG).show();
}//end if
}//end for