Screen Share
Android SDK provides support for sharing the entire screen of the device to the room.
Please note that for a peer to share their screen, their role must have screenshare enabled in the dashboard. Also select the appropriate resolution that you desire the screenshare track should be of.
How to start screenshare from the app (without a custom notification)
To start screen share, app needs to call the startScreenshare
method of HMSSDK
, which takes in two parameters -
The first one is HMSActionResultListener
which is a callback object needed to inform about success
or failure
of the action
The second one is a Intent
which is the result data of MediaProjection permission activity;
the calling app must validate that result code is Activity.RESULT_OK
before
calling this method.
Following is the snippet on how to use this:
How to get Screen Share Status
Application needs to call the isScreenShareActive
method of HMSSDK
.
This method returns a Boolean
which will be true inscase ScreenShare is currently active and being used, and False for inactive state.
How to stop the screenshare and dissmiss the foreground notification from the notification.
To stop the screenshare, create a custom notification and add the following action to it. The image could be anything, but the action has to be gotten from the HMSScreenCaptureService. This will create a "STOP SCREENSHARE" button on the intent.
This pending intent could be passed anywhere you'd like, including on tap of the notification itself.
val notification = NotificationCompat.Builder(getApplication(), "ScreenCapture channel") .addAction(R.drawable.ic_menu_close_clear_cancel, "Stop Screenshare", HMSScreenCaptureService.getStopScreenSharePendingIntent(getApplication())) .build()
How to stop screenshare
Application needs to call the stopScreenshare
method of HMSSDK
and pass an instance of HMSActionResultListener
to listen to the callbacks.
SDK also stops the foreground service on calling this method.
It is advisable to call leave
API from the onDestroy()
of the activity
/ fragment
that
started the screenshare otherwise the foreground service will be running if even user kills the app from the Recents tab.
DONOT forget to add the permission for foreground service
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />