Jump to content
Sign in to follow this  
Turan Can

Android Screenshot not working on new phones >= 10

Recommended Posts

Hi All,

 

I was capturing android screenshot but it doesn't work on newer versions.

 

Return error code;
Project AndroidTest.apk raised exception class EJNIException with message 'java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION'.

 

Permission add on: Foreground Service

I gave the "AndroidManifest" in authorization.

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

 

Another weird problem is the service I added "AndroidManifest".

TJManifest_permission.JavaClass... is not in "FOREGROUND_SERVICE" the service, INSTANT_APP_FOREGROUND_SERVICE

 

Attached is a sample project.

Delphi 11 build project

 

function TForm1.OnActivity(RequestCode, ResultCode: integer; Itt: JIntent): Boolean;
var
  MPro: JMediaProjection;
begin
  Result := false;
  if RequestCode = REQUEST_CODE_SCREEN_CAPTURE then
  begin
    if ResultCode = TJActivity.JavaClass.RESULT_OK then
    begin

 

///Return error code;
///Project AndroidTest.apk raised exception class EJNIException with message 'java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION'.


      MPro := FMedia.getMediaProjection(ResultCode, Itt);
      if MPro <> nil then
      begin
        // ...
        Result := true;
        ShowMessage('Ok')
      end;
    end;
  end;
end;

 

AndroidTest_Screenshot.zip

Edited by Turan Can

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×