Turan Can 3 Posted October 29, 2021 (edited) 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 October 30, 2021 by Turan Can Share this post Link to post
Turan Can 3 Posted October 30, 2021 MediaProjection service type not recognized in android Q - Stack Overflow Is there a "startForeground()" delphide example of this method? TJService.Create.startForeground(); // FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION); I couldn't find it, under which service? ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION Share this post Link to post
Turan Can 3 Posted November 17, 2021 After great effort I solved the problem. Thanks everyone for the unanswered message 😉 Share this post Link to post
Lars Fosdal 1792 Posted November 18, 2021 Thanks for not sharing how you solved it? 1 2 Share this post Link to post