I did screen sharing (tokbox) for my application. It works fine inside my app. But I cannot share screen outside my app... Can anyone plz help? https://tokbox.com/developer/guides/screen-sharing/android/
I had also faced the same issue and had mailed to tokbox support. This was their response:
The way our screen capture code works is that it recursively traverses the view hierarchy and copies those images to a buffer and then send that buffer over on the webrtc data pipe. Hence once the app is pushed to the background, we could not traverse the view hierarchy and copy the image, so screen sharing works until we are in the application (Android or iOS native app). If you want to share the screen view of Opentok app only, it will work but outside the app won't work. It's just to take care of the privacy and security aspects of the mobile app users.
So according to them you cannot share screen outside the application. It will only work when app is in foreground.
After constantly asking the tokbox support team I got the following reply from them:
To screenshare the content outside of your application on Android and iOS can be achieved. For Android, you need to use the Media Projection API together with Vonage/Tokbox Custom Capturer. For iOS, you need to use the iOS ReplayKit together with Vonage/Tokbox Custom Capturer. Basically, the implementation is to get a frame from Media Project API or Replaykit and then pass it via a custom capturer.
Following their response, I found Accelerator Core Android repo which showed how to integrate Media Projection API with tokbox. More specifically these two files: ScreenSharingFragment.java and ScreenSharingCapturer.java
Using these two files I am now able to share screen outside my application.
Note: Apps that target Android 9 (API level 28) or higher should use Foreground services or else your app will crash due to security reasons.