fix: android, no voice call under android 11 (#8440)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
parent
ffed29e632
commit
bbf7d9e08a
@ -116,7 +116,7 @@ class AudioRecordHandle(private var context: Context, private var isVideoStart:
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onVoiceCallStarted(mediaProjection: MediaProjection?): Boolean {
|
fun onVoiceCallStarted(mediaProjection: MediaProjection?): Boolean {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
if (!isSupportVoiceCall()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// No need to check if video or audio is started here.
|
// 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 {
|
fun onVoiceCallClosed(mediaProjection: MediaProjection?): Boolean {
|
||||||
// Return true if `Build.VERSION.SDK_INT < Build.VERSION_CODES.R`, because is was not started.
|
// Return true if not supported, because is was not started.
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
if (!isSupportVoiceCall()) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if (isVideoStart()) {
|
if (isVideoStart()) {
|
||||||
@ -176,9 +176,6 @@ class AudioRecordHandle(private var context: Context, private var isVideoStart:
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun tryReleaseAudio() {
|
fun tryReleaseAudio() {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (isAudioStart() || isVideoStart()) {
|
if (isAudioStart() || isVideoStart()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -233,6 +233,17 @@ class MainActivity : FlutterActivity() {
|
|||||||
result.success(false)
|
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" -> {
|
"on_voice_call_started" -> {
|
||||||
onVoiceCallStarted()
|
onVoiceCallStarted()
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,9 @@ const val START_ACTION = "start_action"
|
|||||||
const val GET_START_ON_BOOT_OPT = "get_start_on_boot_opt"
|
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 SET_START_ON_BOOT_OPT = "set_start_on_boot_opt"
|
||||||
const val SYNC_APP_DIR_CONFIG_PATH = "sync_app_dir"
|
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_SHARED_PREFERENCES = "KEY_SHARED_PREFERENCES"
|
||||||
const val KEY_START_ON_BOOT_OPT = "KEY_START_ON_BOOT_OPT"
|
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
|
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) {
|
fun requestPermission(context: Context, type: String) {
|
||||||
XXPermissions.with(context)
|
XXPermissions.with(context)
|
||||||
.permission(type)
|
.permission(type)
|
||||||
|
@ -418,17 +418,21 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
(isWeb
|
(isWeb
|
||||||
? []
|
? []
|
||||||
: <Widget>[
|
: <Widget>[
|
||||||
IconButton(
|
futureBuilder(
|
||||||
|
future: gFFI.invokeMethod(
|
||||||
|
"get_value", "KEY_IS_SUPPORT_VOICE_CALL"),
|
||||||
|
hasData: (isSupportVoiceCall) => IconButton(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
icon: isAndroid
|
icon: isAndroid && isSupportVoiceCall
|
||||||
? SvgPicture.asset('assets/chat.svg',
|
? SvgPicture.asset('assets/chat.svg',
|
||||||
colorFilter: ColorFilter.mode(
|
colorFilter: ColorFilter.mode(
|
||||||
Colors.white, BlendMode.srcIn))
|
Colors.white, BlendMode.srcIn))
|
||||||
: Icon(Icons.message),
|
: Icon(Icons.message),
|
||||||
onPressed: () => isAndroid
|
onPressed: () =>
|
||||||
|
isAndroid && isSupportVoiceCall
|
||||||
? showChatOptions(widget.id)
|
? showChatOptions(widget.id)
|
||||||
: onPressedTextChat(widget.id),
|
: onPressedTextChat(widget.id),
|
||||||
)
|
))
|
||||||
]) +
|
]) +
|
||||||
[
|
[
|
||||||
IconButton(
|
IconButton(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user