Skip to content

How to use "setCloseAction"? #97

@TechToArt

Description

@TechToArt

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
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions