• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3 Copyright 2014 The Android Open Source Project
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9     http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16-->
17<sample>
18    <name>ScreenCapture</name>
19    <group>Media</group>
20    <package>com.example.android.screencapture</package>
21
22    <minSdk>21</minSdk>
23
24    <strings>
25        <intro>
26<![CDATA[
27This sample demonstrates how to use Media Projection API introduced in Android 5.0 Lollipop. Press
28"Start" to start capturing the screen.
29]]>
30        </intro>
31    </strings>
32
33    <!-- The basic templates have already been enabled. Uncomment more as desired. -->
34    <template src="base"/>
35    <template src="FragmentView"/>
36    <common src="logger"/>
37    <common src="activities"/>
38
39    <metadata>
40        <status>PUBLISHED</status>
41        <categories>Media</categories>
42        <technologies>Android</technologies>
43        <languages>Java</languages>
44        <solutions>Mobile</solutions>
45        <level>INTERMEDIATE</level>
46        <icon>screenshots/icon-web.png</icon>
47        <screenshots>
48            <img>screenshots/main.png</img>
49        </screenshots>
50        <api_refs>
51            <android>android.media.projection.MediaProjection</android>
52            <android>android.media.projection.MediaProjectionManager</android>
53            <android>android.hardware.display.VirtualDisplay</android>
54        </api_refs>
55
56        <description>
57<![CDATA[
58This sample demonstrates how to use Media Projection API to capture device screen in real time and
59show it on a SurfaceView.
60]]>
61        </description>
62
63        <intro>
64<![CDATA[
65Media Projection API lets you capture the current screen through Surface.
66
67To start media projection, you need to get an instance of [MediaProjection][1]. For this, you have
68to call startActivityForResult with an Intent from
69[MediaProjectionManager.createScreenCaptureIntent()][2]. This shows a confirmation dialog to the
70user. When user confirms it, you will get a result code and data in onActivityResult, so pass those
71to [getMediaProjection][3].
72
73Once you get a MediaProjection, use [createVirtualDisplay][4] and bind it to a Surface.
74
75[1]: https://developer.android.com/reference/android/media/projection/MediaProjection.html
76[2]: https://developer.android.com/reference/android/media/projection/MediaProjectionManager.html#createScreenCaptureIntent()
77[3]: https://developer.android.com/reference/android/media/projection/MediaProjectionManager.html#getMediaProjection(int, android.content.Intent)
78[4]: https://developer.android.com/reference/android/media/projection/MediaProjection.html#createVirtualDisplay(java.lang.String, int, int, int, int, android.view.Surface, android.hardware.display.VirtualDisplay.Callback, android.os.Handler)
79]]>
80        </intro>
81    </metadata>
82</sample>
83