pawegio
pawegio

Reputation: 1732

How to finish screen capture using MediaProjectionManager?

I started screen capture intent according to MediaProjectionManager:

var intent = mediaProjectionManager.createScreenCaptureIntent()
startActivityForResult(intent, 0)

... but I have no idea how to stop screen capture. Sample projects for API 21 are still not available.

Upvotes: 1

Views: 2652

Answers (1)

pawegio
pawegio

Reputation: 1732

ok, found solution, firstly save result to MediaProjection instance:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
super<Activity>.onActivityResult(requestCode, resultCode, data)

    if (resultCode == Activity.RESULT_OK) {
        mediaProjection = mediaProjectionManager.getMediaProjection(resultCode, data)
    }
}

and to stop simply execute:

mediaProjection.stop()

Upvotes: 2

Related Questions