android / android/media-samples
How to use "setCloseAction"?
- Dominant language
- Kotlin
- Stars
- 1.4k
- Forks
- 781
- PR merge metrics
- No merged PRs in 30d
Description
I tried to use "PictureInPictureParams.Builder.setCloseAction(RemoteAction)" to finish Activity, but is not work. what should i do?
```
private const val ACTION_STOPWATCH_CONTROL = "stopwatch_control"
private const val EXTRA_CONTROL_TYPE = "control_type"
private const val CONTROL_TYPE_CLOSE = 3
private const val REQUEST_CLOSE = 5
private val broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (intent == null || intent.action != ACTION_STOPWATCH_CONTROL) {
return
}
when (intent.getIntExtra(EXTRA_CONTROL_TYPE, 0)) {
CONTROL_TYPE_CLOSE -> this@MainActivity.finish()
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
...
registerReceiver(broadcastReceiver, IntentFilter(ACTION_STOPWATCH_CONTROL))
}
private fun updatePictureInPictureParams(started: Boolean): PictureInPictureParams {
val params = PictureInPictureParams.Builder()
.setAspectRatio(Rational(16, 9))
.setSeamlessResizeEnabled(false)
.setAutoEnterEnabled(true)
.setCloseAction(
createRemoteAction(
R.drawable.close,
R.string.close,
REQUEST_CLOSE,
CONTROL_TYPE_CLOSE
)
)
.build()
setPictureInPictureParams(params)
return params
}
```
Contributor guide
Research direction
Start in MainActivity at updatePictureInPictureParams and follow the shown createRemoteAction and broadcastReceiver paths. Reproduce the Picture-in-Picture close action, then verify that selecting it triggers the close control and finishes the Activity.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100