Я реализовал в своем приложении функцию PIP, которая работает нормально и имеет кнопку для отключения и включения звука. все работает, но проблема в том, что я не могу обновить значок. Может ли кто-нибудь поделиться мне, как это обновить.
private val isPipSupport by lazy {
packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)
}
private fun setPipMode() {
if (!isPipSupport) return
val pipParams = getPipParams() ?: return
enterPictureInPictureMode(pipParams)
}
private fun getPipParams(): PictureInPictureParams? {
val rect = Rect()
binding.rvPipMode.getGlobalVisibleRect(rect)
val pipParams = PictureInPictureParams.Builder()
.setAspectRatio(Rational(1, 1))
.setSourceRectHint(rect)
.setActions(
getPipButtons()
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
pipParams.setAutoEnterEnabled(true)
}
return pipParams.build()
}
private fun getPipButtons(): MutableList {
val callEndButton = RemoteAction(
Icon.createWithResource(this, R.drawable.ic_pip_end_call),
"End call",
"End call",
PendingIntent.getBroadcast(
this, 0, Intent(this, PipReceiver2::class.java).apply {
action = PIP_BROADCAST_RECEIVER // Use a consistent action string
putExtra(PIP_VALUES, PIP_END_CALL) // Add any extra data you need
}, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
)
val isEnabled = viewModel.micEnabled.value ?: false
val mute_un_mute_icon = if(isEnabled) R.drawable.ic_mic_on else R.drawable.ic_mic_off
val muteUnMuteButton = RemoteAction(
Icon.createWithResource(this, mute_un_mute_icon),
"Mute & Un Mute call",
"Mute & Un Mute call",
PendingIntent.getBroadcast(
this, if(isEnabled) 1 else 2, Intent(this, PipReceiver2::class.java).apply {
action = PIP_BROADCAST_RECEIVER // Use a consistent action string
putExtra(PIP_VALUES, PIP_MUTE_UN_MUTE) // Add any extra data you need
}, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
)
return mutableListOf(muteUnMuteButton, callEndButton)
}
Я пытался вызвать setPipMode(), когда кнопка отключена, но это ничего не меняет.
Я реализовал в своем приложении функцию PIP, которая работает нормально и имеет кнопку для отключения и включения звука. все работает, но проблема в том, что я не могу обновить значок. Может ли кто-нибудь поделиться мне, как это обновить. [code]private val isPipSupport by lazy { packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE) }
private fun setPipMode() { if (!isPipSupport) return val pipParams = getPipParams() ?: return enterPictureInPictureMode(pipParams) }
private fun getPipParams(): PictureInPictureParams? { val rect = Rect() binding.rvPipMode.getGlobalVisibleRect(rect)
val pipParams = PictureInPictureParams.Builder() .setAspectRatio(Rational(1, 1)) .setSourceRectHint(rect) .setActions( getPipButtons() ) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { pipParams.setAutoEnterEnabled(true) } return pipParams.build() }
private fun getPipButtons(): MutableList {
val callEndButton = RemoteAction( Icon.createWithResource(this, R.drawable.ic_pip_end_call), "End call", "End call", PendingIntent.getBroadcast( this, 0, Intent(this, PipReceiver2::class.java).apply { action = PIP_BROADCAST_RECEIVER // Use a consistent action string putExtra(PIP_VALUES, PIP_END_CALL) // Add any extra data you need }, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE ) ) val isEnabled = viewModel.micEnabled.value ?: false val mute_un_mute_icon = if(isEnabled) R.drawable.ic_mic_on else R.drawable.ic_mic_off val muteUnMuteButton = RemoteAction( Icon.createWithResource(this, mute_un_mute_icon), "Mute & Un Mute call", "Mute & Un Mute call", PendingIntent.getBroadcast( this, if(isEnabled) 1 else 2, Intent(this, PipReceiver2::class.java).apply { action = PIP_BROADCAST_RECEIVER // Use a consistent action string putExtra(PIP_VALUES, PIP_MUTE_UN_MUTE) // Add any extra data you need }, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE ) ) return mutableListOf(muteUnMuteButton, callEndButton) } [/code] Я пытался вызвать setPipMode(), когда кнопка отключена, но это ничего не меняет.