覆盖静音模式和/或媒体音量

发布于 2024-09-29 23:59:17 字数 65 浏览 0 评论 0原文

我想覆盖静音模式和/或媒体音量,使手机发出很大的噪音。我知道闹钟可以覆盖静音模式。您如何通过您的应用程序做到这一点?

I want to override the silent mode and/or media volume to make the phone broadcast a loud noise. I know the alarm clock can override silent mode. How do you do this through your app?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧伤慢歌 2024-10-06 23:59:17

您是否询问闹钟应用程序是否可以覆盖静音模式或者代码是否可以覆盖静音模式?

代码答案是肯定的,您可以通过如下代码更改静音模式设置:

AudioManager audio = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
int currentVolume = audio.getStreamVolume(AudioManager.STREAM_RING);
int max = audio.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION);
audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
audio.setStreamVolume(AudioManager.STREAM_RING, max, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);

Are you asking whether the Alarm Clock app can override silent mode or if code can override silent mode?

The code answer is yes, you can change the silent mode setting via code like this:

AudioManager audio = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
int currentVolume = audio.getStreamVolume(AudioManager.STREAM_RING);
int max = audio.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION);
audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
audio.setStreamVolume(AudioManager.STREAM_RING, max, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
枯寂 2024-10-06 23:59:17

我有另一种方法,因为托尼的答案是有效的,但会发生什么,它会改变配置文件,假设您将设备置于静音模式,并且应用程序需要播放任何声音(如闹钟铃声),那么它会将您的配置文件静音更改为铃声模式,然后您需要再次进入静音模式。我说得对吗?

您可以播放下面给出的铃声 isRinging 设置为标志的片段

int volume = audioManager.getStreamVolume(AudioManager.STREAM_ALARM);
if(volume==0)
volume = audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, volume,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
ringtone = RingtoneManager.getRingtone(getApplicationContext(), Uri.parse(ringTonePath));
if(ringtone!=null){
    ringtone.setStreamType(AudioManager.STREAM_ALARM);
    ringtone.play();
    isRinging = true;
}

因此,另一个解决方案是,如果您想以编程方式停止播放,

,或者您可以通过 铃声的 isPlaying() 检查来停止播放我没有更改当前的配置文件,也没有更多代码

I got another way, as the Tony's answer was worked but what happen it will change the profile suppose you put your device into the silent mode and app required to play any sound like alarm tone then it will change your profile silent to ringer mode and then again you need to put into silent mode. Am I right?

So the another solution was you can play the ringtone here snippet given below

int volume = audioManager.getStreamVolume(AudioManager.STREAM_ALARM);
if(volume==0)
volume = audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, volume,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
ringtone = RingtoneManager.getRingtone(getApplicationContext(), Uri.parse(ringTonePath));
if(ringtone!=null){
    ringtone.setStreamType(AudioManager.STREAM_ALARM);
    ringtone.play();
    isRinging = true;
}

isRinging set as flag if you want to programatically stop the playing or you can check the by isPlaying() of ringtone to stop playing

going through this I didn't change the current profile and no more code for that

何止钟意 2024-10-06 23:59:17

Prey 是一款开源手机跟踪器应用程序,如果它的功能之一 - 如果您没有得到更好的答案可以查看来源,看看他们是如何做到的。

Prey is an open source phone tracker app which does this as one if its features - if you don't get a better answer could have a look at the source to see how they did it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文