1

I have a following setup Android Device connected to 2 physical Displays

Display 21442613134359552 (HWC display 0): port=0 pnpId=XXX displayName="XXXMaster"
Display 21442613134359553 (HWC display 1): port=1 pnpId=XXX displayName="XXXMaster"

I'm trying to start the screen projection on the secondary display

// Getting Media Projection and Display Managers.
MediaProjectionManager mpm =
     (MediaProjectionManager) activity.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
DisplayManager dm =
     (DisplayManager) activity.getSystemService(Context.DISPLAY_SERVICE);

// Adding an option to start activity on the Scondary Display.
ActivityOptions options = ActivityOptions.makeBasic();
options.setLaunchDisplayId(dm.getDisplays()[1].getDisplayId());
startActivityForResult(
    mpm.createScreenCaptureIntent(), RESULT_OK, options.toBundle()
);

when I am running the code above, the system is popping up a message

App does not support launch on the secondary displays

the application which I am building has system-app privileges, but still, that does not improve the situation.

Questions

  • Is it possible to project secondary display if the app is running as a system application

  • Is it possible to project secondary display if the app is running as a NON-system application

  • Is it possible to specify display id while creating virtual display

    MediaProjection.createVirtualDisplay
    
Viktor Apoyan
  • 10,655
  • 22
  • 85
  • 147
  • "I'm trying to start the screen projection on the secondary display" -- what do you mean by this? `createScreenCaptureIntent()` is a system-supplied `Intent` that, when used with `startActivityForResult()`, shows a dialog to ask the user to grant permission for the screen recording. Your code is trying to show that dialog on the secondary display. The system app showing that dialog might not support that (hence the error). Also, if that secondary display is not a touchscreen, the user might not be able to accept the dialog. – CommonsWare Oct 12 '21 at 10:49
  • @CommonsWare, if I configure options like `options.setLaunchDisplayId(dm.getDisplays()[0].getDisplayId());` for the screen with ID 0, then I see dialog and if I press "Start Now" then on another device I can see projected screen when I use id 1 instead then I get same dialog press "Start Now" and then I see the message "App does not support launch on the secondary displays" and on the device I still see display number 0 – Viktor Apoyan Oct 12 '21 at 10:57
  • @CommonsWare my both displays are touchscreen. What I want to achieve let's say you have 2 displays, on the one you are running Application A, on another Application B, so now you are running Projection Application which shows you a dialog, hey I found 2 displays which one you one to project, you select number 2 and then on your device you should see Application B – Viktor Apoyan Oct 12 '21 at 11:00
  • @CommonsWare if you have 2 displays connected to the device and you simply start screen projection, by default system will choose main display (with id 0) and start casting that one, the question here is, is it possible at all to start projection of != 0 display and if yes how it can be done. Thanks – Viktor Apoyan Oct 12 '21 at 11:01
  • I do not know if `MediaProjection` supports multiple displays. I would have expected to see a `displayId` or similar parameter on `createVirtualDisplay()`, and there does not appear to be one. When I did work with `MediaProjection` years ago, I only tried with a single display. Other than trying different `DisplayManager` flags for the `flags` parameter to `createVirtualDisplay()`, I do not know to accomplish what you are seeking. – CommonsWare Oct 12 '21 at 11:12

0 Answers0