问题描述
安装后,我将设备设置为管理员。
应用程序处于LockTask(KIOSK模式)时,媒体播放器没有播放任何音频
我写了一个启用/禁用KIOSK MODE的句柄
我正在尝试从res / raw播放一个简单的音频文件。设备的音量设置为高。
mediaPlayer = MediaPlayer.create(context,R.raw.panic_ring)
mediaPlayer?.start()
mediaPlayer?.isLooping = true
但是我仍然听不到任何来自设备的声音
如果我通过调用enableKioskMode(false)
来禁用KIOSK模式,那么我会听到很好的声音。
解决方法
- 确保您尚未设置 DevicePolicyManager中的用户限制 即UserManager.DISALLOW_ADJUST_VOLUME
- 添加代码以将手机置于满音量的RINGER模式
private fun setDeviceOnRingerMode(applicationContext: Context) {
val am: AudioManager? =
applicationContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager?
am?.ringerMode = AudioManager.RINGER_MODE_NORMAL
Settings.System.putInt(
applicationContext.contentResolver,android.provider.Settings.System.NOTIFICATION_SOUND,1
)
}