{"id":4230,"date":"2021-11-12T14:07:48","date_gmt":"2021-11-12T06:07:48","guid":{"rendered":"https:\/\/www.enablex.io\/developer\/?page_id=4230"},"modified":"2022-04-08T18:49:00","modified_gmt":"2022-04-08T10:49:00","slug":"screen-share","status":"publish","type":"page","link":"https:\/\/doc.smartflomeet.ttns.in\/developer\/video-api\/client-api\/android-toolkit\/screen-share\/","title":{"rendered":"Screen Share : Android SDK &#8211; Video API"},"content":{"rendered":"\n<h3>Table of Contents<\/h3>\n\n\n\n<ul><li><a href=\"#start-share\">Start Screen Share<\/a><\/li><li><a href=\"#stop-share\">Stop Screen Share<\/a><\/li><li><a href=\"#force-stop-share\">Force Stop other&#8217;s Screen Share<\/a><\/li><\/ul>\n\n\n\n<p>To support Screen-Sharing in the Room, you need to enable Screen-Sharing during <a rel=\"noreferrer noopener\" href=\"..\/..\/..\/server-api\/rooms-route\/#create-room\" target=\"_blank\">Room Creation<\/a> by setting: <code>{ \"screen_share\": true; })<\/code> in the JSON Payload. To receive Shared Screen, you need to subscribe to the Screen-Share Stream ID# 101 and play it on the Video Player.<\/p>\n\n\n\n<p><strong>Note<\/strong>: If you have Android 11 (API level 30) or higher, then you must create a foreground service and access the camera or microphone in the foreground service. Declare the&nbsp;<code>camera<\/code>&nbsp;or&nbsp;<code>microphone<\/code>&nbsp;foreground service types, respectively, as attributes of your&nbsp;<code>&lt;service&gt;<\/code>&nbsp;component. [ <a href=\"#implement-foreground-service\">Read More&#8230;<\/a> ]<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<a name=\"start-share\"><\/a>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3>Start Screen Sharing<\/h3>\n\n\n\n<p>The&nbsp;<code>EnxRoom.startScreenShare()<\/code>&nbsp;method is used to create a Screen-Sharing Stream @ 6fps to publish in the Room.&nbsp;Screen Sharing continues even when the Application runs in the background.<\/p>\n\n\n\n<p><strong>Class:<\/strong> EnxRoom<\/p>\n\n\n\n<p><strong>Observer<\/strong>: <code>public void setScreenShareObserver(EnxScreenShareObserver-Object) <\/code><\/p>\n\n\n\n<p><strong>Method:<\/strong> <code>public void startScreenShare()<\/code><\/p>\n\n\n\n<p><strong>Callbacks:<\/strong><\/p>\n\n\n\n<p><code>onScreenSharedStarted<\/code> &#8211; Notification to everyone in the Room when Screen-Sharing starts. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ Initiate Screen Share Observer to receive Callbacks\nroom.setScreenShareObserver(this);\n\n\/\/ Start Screen Share\nroom.startScreenShare();\t\n\n\/\/ A new Screen Share Stream is available, receive Information\npublic void onScreenSharedStarted(EnxStream enxStream) {\n\t\/\/ Get EnxPlayerView from ensStream\n\t\/\/ And add to View\n\tyourView.addView(enxStream.mEnxPlayerView);\n} <\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<a name=\"stop-share\"><\/a>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3>Stop Screen Sharing<\/h3>\n\n\n\n<p>The <code>EnxRoom.stopScreenShare()<\/code>&nbsp;method is used to stop the ongoing Screen-Sharing.<\/p>\n\n\n\n<p><strong>Class:<\/strong> EnxRoom<\/p>\n\n\n\n<p><strong>Method:<\/strong> <code>public void stopScreenShare()<\/code> <\/p>\n\n\n\n<p><strong>Callbacks:<\/strong><\/p>\n\n\n\n<p><code>onScreenSharedStopped<\/code> &#8211; Notification to everyone in the Room when Screen-Sharing stops.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">room.stopScreenShare(); \/\/ Stop Screen Share\n\n\/\/ Screen Share has stopped. Receive Information\npublic void onScreenSharedStopped(EnxStream enxStream){\n\/\/ And remove View from yourView\nyourView.removeAllViews();\n}<\/pre>\n\n\n\n<p><strong>Error Codes \/ Exceptions<\/strong>:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Code<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>5107<\/td><td>Repeated <code>startScreenShare()<\/code> call made while previous request is in process.<\/td><\/tr><tr><td>1170<\/td><td>Screen-Sharing not supported in your subscription.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<a name=\"force-stop-share\"><\/a>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3>Force Stop other&#8217;s Screen Sharing<\/h3>\n\n\n\n<p><strong>Availability:<\/strong> Android SDK 2.1.2+ <\/p>\n\n\n\n<p>If moderator wishes to force stop any ongoing Screen Share by other user in the Room, he can do so by using <code>EnxRoom.stopAllSharing()<\/code> method. Note, this is Moderator exclusive feature, can&#8217;t be executed from Participant&#8217;s end point.<\/p>\n\n\n\n<p>This method also force stops any ongoing Canvas Streaming.<\/p>\n\n\n\n<p><strong>Class:<\/strong> <code>EnxRoom<\/code><\/p>\n\n\n\n<p><strong>Observer<\/strong>: <code>ACK CallBack<\/code><\/p>\n\n\n\n<p><strong>Method:<\/strong> <code>public void stopAllSharing()<\/code> <\/p>\n\n\n\n<p><strong>Callbacks:<\/strong><\/p>\n\n\n\n<p><code>onStopAllSharingACK<\/code> &#8211; Notification to everyone in the Room when Screen-Sharing stops.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">EnxRoom.stopAllSharing()     \/\/ Force Stop the Shared Screen\n\n \n\/\/ Notification to all when share stops\npublic void onStopAllSharingACK(JSONObject jsonObject) {\n\t\/\/ Code here... to handle your UI\n}<\/pre>\n\n\n\n<a name=\"implement-foreground-service\"><\/a>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2>Implementing a Foreground Service<\/h2>\n\n\n\n<p>The implementation part is quite similar to that of a service. Let\u2019s check the step-by-step procedure for doing this.<\/p>\n\n\n\n<ol><li>Create a foreground service<\/li><li>Add permission in manifest<\/li><li>Register foreground service in manifest<\/li><\/ol>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3>Create a Foreground Service<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">public class ForegroundService extends Service {\npublic static final String CHANNEL_ID = \"ForegroundServiceChannel\";\nint NOTIFICATION_ID = 121412;\npublic NotificationManager notificationManager;\n@Override\npublic void onCreate() {\nsuper.onCreate();\n}\n\n@Override\npublic int onStartCommand(Intent intent, int flags, int startId) {\nif (intent != null) {\nif (intent.getAction().equals(\"ACTION_START\")) {\nshowOnGoingCall();\n}else {\nstopForegroundService();\n}\n}\nreturn START_NOT_STICKY;\n}\n@Override\npublic void onDestroy() {\nsuper.onDestroy();\n}\n@Nullable\n@Override\npublic IBinder onBind(Intent intent) {\nreturn null;\n}\nprivate void showOnGoingCall() {\nString app_Name = getResources().getString(R.string.app_name);\nIntent notificationIntent = new Intent(this, VideoConferenceActivity.class);\nnotificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);\nPendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);\nString CHANNEL_ID = getResources().getString(R.string.app_name);\nNotification notification;\nif (Build.VERSION.SDK_INT &gt;= 26) {\nNotificationChannel channel = new NotificationChannel(CHANNEL_ID, \"Sync Service\", NotificationManager.IMPORTANCE_HIGH);\nchannel.setDescription(\"Service Name\");\nnotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);\nnotificationManager.createNotificationChannel(channel);\n\n\nnotification = new NotificationCompat.Builder(this, CHANNEL_ID)\n.setContentTitle(app_Name)\n.setCategory(Notification.CATEGORY_SERVICE)\n.setContentText(\"Ongoing call\")\n.setOngoing(true)\n.setSmallIcon(R.mipmap.ic_launcher_round)\n.setContentIntent(pendingIntent)\n.build();\n} else {\nnotification = new Notification.Builder(this)\n.setContentTitle(\"Project Name\")\n.setOngoing(true)\n.setContentText(\"Ongoing call\")\n.setSmallIcon(R.drawable.ic_launcher)\n.setContentIntent(pendingIntent).build();\nnotificationManager =\n(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);\n}\nstartForeground(NOTIFICATION_ID, notification);\n}\nprivate void stopForegroundService() {\nstopForeground(true);\nstopSelf();\n}\n}\n<\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3>Add Permission in Manifest<\/h3>\n\n\n\n<p>We need to request foreground service permission for Android 9 (API level 28) or higher. We need to specify the permission below in our manifest file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;uses-permission android:name=\"android.permission.FOREGROUND_SERVICE\" \/&gt;<\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3>Register Foreground Service in Manifest<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;service    android:name=\".activity.ForegroundService\"    android:enabled=\"true\"    android:foregroundServiceType=\"mediaProjection\"    android:exported=\"true\" \/&gt;Call Foreground Service in VideoConferenceActivity public void startService() {        Intent serviceIntent = new Intent(VideoConferenceActivity.this, ForegroundService.class);        serviceIntent.setAction(\"ACTION_START\");\/\/        serviceIntent.putExtra(\"inputExtra\", \"Foreground Service Example in Android\");        ContextCompat.startForegroundService(VideoConferenceActivity.this, serviceIntent);    }    public void stopService() {        Intent serviceIntent = new Intent(VideoConferenceActivity.this, ForegroundService.class);        serviceIntent.setAction(\"ACTION_STOP\");        stopService(serviceIntent);\/\/        ContextCompat.startForegroundService(getActivity(), serviceIntent);    } stopService() call in onDestroy method and startService() call in onStart method<\/pre>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<hr class=\"wp-block-separator is-style-wide\"\/>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<p>\u2190 <a href=\"..\/file-share\/\">File Sharing<\/a><\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column\">\n<p class=\"has-text-align-center\"><a href=\"..\/\">Index<\/a><\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column\">\n<p class=\"has-text-align-right\"><a href=\"..\/canvas-streaming\/\"><\/a><a href=\"..\/canvas-streaming\/\">Canvas Streaming<\/a> \u2192<a href=\"\/developer\/how-to-use\/\"><\/a><\/p>\n<\/div>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Table of Contents Start Screen Share Stop Screen Share Force Stop other&#8217;s Screen Share To support Screen-Sharing in the Room, you need to enable Screen-Sharing during Room Creation by setting: { &#8220;screen_share&#8221;: true; }) in the JSON Payload. To receive Shared Screen, you need to subscribe to the Screen-Share Stream ID# 101 and play it on the Video Player. Note: If you have Android 11 (API level 30) or higher,&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"parent":3740,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"ub_ctt_via":""},"featured_image_src":null,"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"featured":false,"featured-large":false},"uagb_author_info":{"display_name":"vcxdevwpadmin","author_link":"https:\/\/doc.smartflomeet.ttns.in\/developer\/author\/vcxdevwpadmin\/"},"uagb_comment_info":0,"uagb_excerpt":"Table of Contents Start Screen Share Stop Screen Share Force Stop other&#8217;s Screen Share To support Screen-Sharing in the Room, you need to enable Screen-Sharing during Room Creation by setting: { \"screen_share\": true; }) in the JSON Payload. To receive Shared Screen, you need to subscribe to the Screen-Share Stream ID# 101 and play it&hellip;","_links":{"self":[{"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/pages\/4230"}],"collection":[{"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/comments?post=4230"}],"version-history":[{"count":0,"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/pages\/4230\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/pages\/3740"}],"wp:attachment":[{"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/media?parent=4230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}