blob: 956e846b0aec65238051b3292c7b19c9731e3758 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
Copyright 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
This sample demonstrates how to use Media Projection API introduced in Android 5.0 Lollipop. Press
"Start" to start capturing the screen.
<!-- The basic templates have already been enabled. Uncomment more as desired. -->
<template src="base"/>
<template src="FragmentView"/>
<common src="logger"/>
<common src="activities"/>
This sample demonstrates how to use Media Projection API to capture device screen in real time and
show it on a SurfaceView.
Media Projection API lets you capture the current screen through Surface.
To start media projection, you need to get an instance of [MediaProjection][1]. For this, you have
to call startActivityForResult with an Intent from
[MediaProjectionManager.createScreenCaptureIntent()][2]. This shows a confirmation dialog to the
user. When user confirms it, you will get a result code and data in onActivityResult, so pass those
to [getMediaProjection][3].
Once you get a MediaProjection, use [createVirtualDisplay][4] and bind it to a Surface.
[3]:, android.content.Intent)
[4]:, int, int, int, int, android.view.Surface, android.hardware.display.VirtualDisplay.Callback, android.os.Handler)