Fixed AudioManager related SDK version test
This commit is contained in:
@@ -899,14 +899,14 @@ object Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun isSpeakerPhoneOn(am: AudioManager): Boolean {
|
fun isSpeakerPhoneOn(am: AudioManager): Boolean {
|
||||||
return if (Build.VERSION.SDK_INT > 33)
|
return if (Build.VERSION.SDK_INT >= 31)
|
||||||
am.communicationDevice!!.type == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER
|
am.communicationDevice!!.type == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER
|
||||||
else
|
else
|
||||||
am.isSpeakerphoneOn
|
am.isSpeakerphoneOn
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setSpeakerPhone(executor: Executor, am: AudioManager, enable: Boolean) {
|
private fun setSpeakerPhone(executor: Executor, am: AudioManager, enable: Boolean) {
|
||||||
if (Build.VERSION.SDK_INT > 33) {
|
if (Build.VERSION.SDK_INT >= 31) {
|
||||||
val current = am.communicationDevice!!.type
|
val current = am.communicationDevice!!.type
|
||||||
Log.d(TAG, "Current com dev/mode is $current/${am.mode}")
|
Log.d(TAG, "Current com dev/mode is $current/${am.mode}")
|
||||||
var speakerDevice: AudioDeviceInfo? = null
|
var speakerDevice: AudioDeviceInfo? = null
|
||||||
@@ -971,7 +971,7 @@ object Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun toggleSpeakerPhone(executor: Executor, am: AudioManager) {
|
fun toggleSpeakerPhone(executor: Executor, am: AudioManager) {
|
||||||
if (Build.VERSION.SDK_INT > 33) {
|
if (Build.VERSION.SDK_INT >= 31) {
|
||||||
if (am.communicationDevice!!.type == AudioDeviceInfo.TYPE_BUILTIN_EARPIECE)
|
if (am.communicationDevice!!.type == AudioDeviceInfo.TYPE_BUILTIN_EARPIECE)
|
||||||
setSpeakerPhone(executor, am, true)
|
setSpeakerPhone(executor, am, true)
|
||||||
else if (am.communicationDevice!!.type == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER)
|
else if (am.communicationDevice!!.type == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER)
|
||||||
@@ -994,7 +994,7 @@ object Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun clearCommunicationDevice(am: AudioManager) {
|
private fun clearCommunicationDevice(am: AudioManager) {
|
||||||
if (Build.VERSION.SDK_INT > 33) {
|
if (Build.VERSION.SDK_INT >= 31) {
|
||||||
am.clearCommunicationDevice()
|
am.clearCommunicationDevice()
|
||||||
} else {
|
} else {
|
||||||
if (am.isSpeakerphoneOn)
|
if (am.isSpeakerphoneOn)
|
||||||
|
|||||||
Reference in New Issue
Block a user