Android静音/取消静音手机 [英] Android mute/unmute phone
本文介绍了Android静音/取消静音手机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的目标是支持2种操作:
My goal is to support 2 operations:
-
静音电话(可能启用/禁用了振动功能),因此当接到电话或短信时,它不会发出声音
mute phone (possibly with vibrations enabled/disabled), so when a call or sms is received it won't make noise
取消静音并恢复静音之前的音量
unmute phone and restore the volume to the state before muting phone
我该怎么做? AndroidManifest需要什么权限?
How can I do this? What permissions are required in AndroidManifest?
推荐答案
这是振动进入清单文件的权限
This is the permission for vibrate into the manifest file
<uses-permission android:name="android.permission.VIBRATE" />
这是为了使设备处于振动的静音模式
this is for to put the device in silent mode with vibrate
AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
这是用于进入振铃模式
AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
audioManager.setStreamVolume(AudioManager.STREAM_RING, maxVolume, AudioManager.FLAG_SHOW_UI + AudioManager.FLAG_PLAY_SOUND);
这篇关于Android静音/取消静音手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文