0
  Intent dialogIntent = new Intent(BackgroundService.this, ScreenShotActivity.class);
  dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  startActivity(dialogIntent);

I want to ask you if starting the activity ScreenShotActivity.class, which is the class for the MediaProjection implementation, from a background-service is the only way to record everything happening on screen.

Source: How to take a Screenshot from a background-service class using MediaProjection API?

Or is it possible to implement everything of the MediaProjection API inside the service itself, without needing an "util" activity?

zaxunobi
  • 51
  • 9

1 Answers1

2

is it possible to implement everything of the MediaProjection API inside the service itself, without needing an "util" activity?

No. The user needs to agree to allow your app to record the screen, and the system-supplied dialog for that is displayed via startActivityForResult(). That, in turn, requires an activity.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • So the best approach would be to wait for the recording, started in the activity, to be over and then start the service and perform the actions on the video recording inside the service? – zaxunobi Oct 11 '21 at 20:57
  • @zaxunobi: The recording itself can be done completely in the service, but you need the result of the `startActivityForResult()` call to start the recording. [This sample app](https://github.com/commonsguy/cw-omnibus/tree/v9.0/MediaProjection/andcorder) is old but it demonstrates the basic technique. – CommonsWare Oct 11 '21 at 20:59