Questions tagged [android-mediaprojection]

MediaProjection is an Android class that facilitates capturing the screen and recording system audio.

The android.media.projection classes were introduced in Android API 21 to allow applications to record still images, video, and (potentially) audio from the device. In previous releases, applications were only allowed to capture their own rendering, and different approaches were required for View-based UI and OpenGL ES rendering.

Because capturing content outside of the current application has security implications, applications wishing to use these features must get permission from the user first. This is handled through the MediaProjectionManager.

An official screen capture example can be found on github.

The images captured by the MediaProjection are sent to a virtual display, which takes a Surface as an argument. The Surface can be provided by a SurfaceView (for immediate display), an ImageReader (for access from software), constructed from a SurfaceTexture (for use as an OpenGL ES texture), or by MediaCodec/MediaRecorder (for video encoding).

178 questions
5
votes
0 answers

How to use MediaProjection to capture screen in a Service?

As we know, we can use Android MediaProjection API to capture screen in an Activity, but I want to capture screen in a thread of a Service. But Android Service has no onActivityResult() method that MediaProjection need to do something. It seems that…
5
votes
0 answers

ScreenCapture via MediaProjection without user intervention in Kiosk apps - Android

I work for a digital signage company which has Android devices running in kiosk mode. Lately, we wanted to add screen capture for debugging. The easiest way to do that was to use getWindow().getDecorView().getRootView().getDrawingCache() to…
5
votes
0 answers

using media projection with media recorder produce corrupted video

I am trying to use media projection api that became available on lollipop devices (android 5 and above), now I realized 2 ways of using this api with android: First way: Using the mediacodec and media muxer. Second way Using the media recorder…
5
votes
0 answers

How to check whether Media Projection API Service Permission Enabled or not

I am working in an app where I am taking screenshots using Media Projection API. I am able to successfully get the screenshot of the user foreground screen but unfortunately am not able to get the state whether user has already provided Screen…
5
votes
2 answers

How to trim video with MediaCodec

I'm trying to record the screen with MediaProjection API. I want to trim the video that was recorded by the media projection. Is there a way to do that without using any 3rd party dependency?
mnagy
  • 1,085
  • 1
  • 17
  • 36
5
votes
0 answers

Android: How to record the orientation change in MediaProjection API

I am trying to record the orientation change(Landscape, Upsidedown landscape and upsidedown vertical) with the screen recorder api of android(mediaprojection api) As in I want the recorded video's orientation to be changed when the screen's…
5
votes
1 answer

Android resize VirtualDisplay

I have a few problems (actually more, but these are the more critical ones) with Android's MediaProjection API. Reading the graphics architecture won't really help, so I'm just looking to understand if I skipped something in my code flow. Let's…
5
votes
0 answers

Use Output of Android MediaProjection API as Source for libjingle WebRTC Library?

I am trying to create an Android app that utilizes the libjingle WebRTC native Android library to project the users Android desktop to a peer using WebRTC. To that end, I have successfully used the pristine.io libjingle mirror to recreate the…
Rob Droid
  • 173
  • 1
  • 11
4
votes
1 answer

System audio streaming on Android over Webrtc

I am trying to build a screensharing application on Android using Webrtc. I am able to share the screen using mediaprojection+webrtc but not able to share the system audio. Mediaprojection added support to capturing system audio from API 29 (Android…
4
votes
3 answers

How to exclude overlay from screenshot?

Based in this answer I think that exists a solution at least to system apps (or probably also in rooted devices?). Happens that i not understood the code example linked on answer comments. Someone could explain a step by step to achieve this please…
user13342561
4
votes
2 answers

Android Screen Recording How-To - Landscape recording, video recorded plays in full-screen vs partial-screen

I am currently using Media Projection + Media Recorder to do screen recording. The problem I am facing is, when my phone is in Landscape mode during recording, the video recorded will only be shown in the center/middle of the screen with black on…
4
votes
2 answers

Black edges around the taken screenshot

I'm following this example : package com.mtsahakis.mediaprojectiondemo; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import…
Abanoub
  • 3,623
  • 16
  • 66
  • 104
4
votes
2 answers

Android record screen but only specific 'layers'/views

I use the MediaProjection API to record a screen in Android. Now I want to know whether it's possible to create a let's say "hidden" view which you actually can see but not in the video thus the view shouldn't be recorded. Furthermore is it possible…
User0101
  • 95
  • 2
  • 6
4
votes
0 answers

Resize Surface When Resizing VirtualDisplay

A while ago I askedthis question which received an answer. I have implemented an intermediary Surface as the answer suggested, but now I've run into another problem. At some points in time during my application, my VirtualDisplay can change…
EncodedNybble
  • 265
  • 2
  • 11
4
votes
2 answers

MediaProjection producing distorted screenshot

I managed to get screenshots but the result is like this: Original: This is my code which i took from a few sources: final ImageReader ir = ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 2); VirtualDisplay vd=…
hoshiKuzu
  • 866
  • 1
  • 12
  • 30
1
2
3
11 12