How to use "setCloseAction"?

Open
#97 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
android, kotlin
Domain
mobile

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.

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 -> [email protected]()
            }
        }
    }

    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
    }
Dominant language
Kotlin
Stars
1.4k
Forks
777
Avg merge
1m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from android/media-samples

All issues in android/media-samples

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.