响,即使在振铃Android是静音报警 [英] ring an alarm even when ringer is muted in android

查看:161
本文介绍了响,即使在振铃Android是静音报警的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,是有可能响起,即使铃声静音报警?如果是,怎么样。而且,我可以设置其体积介于两者之间,而不仅仅是maxvolume?在此先感谢

 为(SmsMessage消息:消息){
        如果(msg.getMessageBody()。包含(firealert)){            乌里警报= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
             如果(警告== NULL){
                 //警报为null,使用备份
                 警报= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                 如果(警告== NULL){
                     //警报备份为空,用第二个备份
                     警报= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
                 }
             }
             铃声R = RingtoneManager.getRingtone(context.getApplicationContext(),警告);
             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(),报警开始,Toast.LENGTH_LONG).show();
        }//万一
    } //结束了


解决方案

东西来看看:

AudioManager.getRingerMode / setRingerMode。将其设置为RINGER_MODE_NORMAL确保手机不静音或设置为振动。 (虽然你可能想先检查状态,让您可以存储,而你的报警被清除后重置价值)。

 如果(aManager.getRingerMode()!= AudioManager.RINGER_MODE_NORMAL)
    aManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);

如果你想音量设置为50%,然后检查AudioManager.getStreamMaxVolume,然后除以2,例如。它可能会更好地让用户进行配置,虽然。使用搜索栏让他树立了preferred体积(其中,再次,你可以你的闹钟播放完毕后恢复为正常)。

  RingerVolumeBar =(搜索栏)findViewById(R.id.seekBar1);
RingerVolumeBar.setOnSeekBarChangeListener(新OnSeekBarChangeListener()
{
   @覆盖
   公共无效onProgressChanged(搜索栏搜索栏,
                        INT进步,布尔FROMUSER)
   {
   aManager.setStreamVolume(AudioManager.STREAM_RING,
                            进步,AudioManager.FLAG_PLAY_SOUND);
   //记录新的设置,以便您可以加载或复位回来后
   ...
   }
});

sir, is it possible to ring an alarm even when ringer is muted? if yes, how. and also, can i set its volume to something in between and not just maxvolume? thanks in advance

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

解决方案

Things to look at:

AudioManager.getRingerMode / setRingerMode. Set it to RINGER_MODE_NORMAL to ensure the phone isn't muted or set to vibrate. (Although you might want to check the state first, so you can store it and reset the value after your alarm is cleared.)

if ( aManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL )
    aManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);

If you want to set volume to 50% then check AudioManager.getStreamMaxVolume and then divide that by 2, for example. It would probably be better to let the user configure it, though. Use a SeekBar to have him set a preferred volume (which, again, you could reset back to normal after your alarm plays).

RingerVolumeBar = (SeekBar) findViewById(R.id.seekBar1);
RingerVolumeBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
   @Override
   public void onProgressChanged(SeekBar seekBar,
                        int progress, boolean fromUser)
   {
   aManager.setStreamVolume(AudioManager.STREAM_RING,
                            progress, AudioManager.FLAG_PLAY_SOUND);
   // record new setting so you can load it up or reset it back later
   ...
   }
});

这篇关于响,即使在振铃Android是静音报警的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆