fix: android, no voice call under android 11 (#8440)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-06-22 08:10:54 +08:00 committed by GitHub
parent ffed29e632
commit bbf7d9e08a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 37 additions and 17 deletions

View File

@ -116,7 +116,7 @@ class AudioRecordHandle(private var context: Context, private var isVideoStart:
}
fun onVoiceCallStarted(mediaProjection: MediaProjection?): Boolean {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
if (!isSupportVoiceCall()) {
return false
}
// No need to check if video or audio is started here.
@ -127,8 +127,8 @@ class AudioRecordHandle(private var context: Context, private var isVideoStart:
}
fun onVoiceCallClosed(mediaProjection: MediaProjection?): Boolean {
// Return true if `Build.VERSION.SDK_INT < Build.VERSION_CODES.R`, because is was not started.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
// Return true if not supported, because is was not started.
if (!isSupportVoiceCall()) {
return true
}
if (isVideoStart()) {
@ -176,9 +176,6 @@ class AudioRecordHandle(private var context: Context, private var isVideoStart:
}
fun tryReleaseAudio() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
return
}
if (isAudioStart() || isVideoStart()) {
return
}

View File

@ -233,6 +233,17 @@ class MainActivity : FlutterActivity() {
result.success(false)
}
}
GET_VALUE -> {
if (call.arguments is String) {
if (call.arguments == KEY_IS_SUPPORT_VOICE_CALL) {
result.success(isSupportVoiceCall())
} else {
result.error("-1", "No such key", null)
}
} else {
result.success(null)
}
}
"on_voice_call_started" -> {
onVoiceCallStarted()
}

View File

@ -47,6 +47,9 @@ const val START_ACTION = "start_action"
const val GET_START_ON_BOOT_OPT = "get_start_on_boot_opt"
const val SET_START_ON_BOOT_OPT = "set_start_on_boot_opt"
const val SYNC_APP_DIR_CONFIG_PATH = "sync_app_dir"
const val GET_VALUE = "get_value"
const val KEY_IS_SUPPORT_VOICE_CALL = "KEY_IS_SUPPORT_VOICE_CALL"
const val KEY_SHARED_PREFERENCES = "KEY_SHARED_PREFERENCES"
const val KEY_START_ON_BOOT_OPT = "KEY_START_ON_BOOT_OPT"
@ -60,6 +63,11 @@ data class Info(
var width: Int, var height: Int, var scale: Int, var dpi: Int
)
fun isSupportVoiceCall(): Boolean {
// https://developer.android.com/reference/android/media/MediaRecorder.AudioSource#VOICE_COMMUNICATION
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
}
fun requestPermission(context: Context, type: String) {
XXPermissions.with(context)
.permission(type)

View File

@ -418,17 +418,21 @@ class _RemotePageState extends State<RemotePage> {
(isWeb
? []
: <Widget>[
IconButton(
color: Colors.white,
icon: isAndroid
? SvgPicture.asset('assets/chat.svg',
colorFilter: ColorFilter.mode(
Colors.white, BlendMode.srcIn))
: Icon(Icons.message),
onPressed: () => isAndroid
? showChatOptions(widget.id)
: onPressedTextChat(widget.id),
)
futureBuilder(
future: gFFI.invokeMethod(
"get_value", "KEY_IS_SUPPORT_VOICE_CALL"),
hasData: (isSupportVoiceCall) => IconButton(
color: Colors.white,
icon: isAndroid && isSupportVoiceCall
? SvgPicture.asset('assets/chat.svg',
colorFilter: ColorFilter.mode(
Colors.white, BlendMode.srcIn))
: Icon(Icons.message),
onPressed: () =>
isAndroid && isSupportVoiceCall
? showChatOptions(widget.id)
: onPressedTextChat(widget.id),
))
]) +
[
IconButton(