@@ -345,6 +345,77 @@ toggleScreencast({screencastMetadata: { displayName: "Annie's desktop" }});
345
345
346
346
Use track metadata to differentiate between video and screencast tracks.
347
347
348
+ ### Android foreground service
349
+
350
+ In order for the call to continue running when app is in background, you need to
351
+ set up and start a foreground service. You can use a 3rd party library for this,
352
+ for example [ notifee] ( https://notifee.app/ ) .
353
+
354
+ In ` AndroidManifest.xml ` specify necessary permissions:
355
+
356
+ ``` xml
357
+ <uses-permission android : name =" android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
358
+ <uses-permission android : name =" android.permission.FOREGROUND_SERVICE_CAMERA" />
359
+ <uses-permission android : name =" android.permission.FOREGROUND_SERVICE_MICROPHONE" />
360
+ ```
361
+
362
+ And add foreground service:
363
+
364
+ ``` xml
365
+ <application
366
+ ...
367
+ >
368
+ ...
369
+ <service
370
+ android : name =" app.notifee.core.ForegroundService"
371
+ android : foregroundServiceType =" mediaProjection|camera|microphone" />
372
+ </application >
373
+ ```
374
+
375
+ Then to start the foreground service:
376
+
377
+ ``` ts
378
+ import notifee , { AndroidImportance } from ' @notifee/react-native' ;
379
+
380
+ const startForegroundService = async () => {
381
+ if (Platform .OS === ' android' ) return ;
382
+ const channelId = await notifee .createChannel ({
383
+ id: ' video_call' ,
384
+ name: ' Video call' ,
385
+ lights: false ,
386
+ vibration: false ,
387
+ importance: AndroidImportance .DEFAULT ,
388
+ });
389
+
390
+ await notifee .displayNotification ({
391
+ title: ' Your video call is ongoing' ,
392
+ body: ' Tap to return to the call.' ,
393
+ android: {
394
+ channelId ,
395
+ asForegroundService: true ,
396
+ ongoing: true ,
397
+ pressAction: {
398
+ id: ' default' ,
399
+ },
400
+ },
401
+ });
402
+ };
403
+ ```
404
+
405
+ Don't forget to also stop the service when the call has ended:
406
+
407
+ ``` ts
408
+ notifee .stopForegroundService ();
409
+ ```
410
+
411
+ Also add this code in your ` index.js ` to register the service:
412
+
413
+ ``` js
414
+ notifee .registerForegroundService ((notification ) => {
415
+ return new Promise (() => {});
416
+ });
417
+ ```
418
+
348
419
### Developing
349
420
350
421
Run ` ./scripts/init.sh ` in the main directory to install swift-format and set up
0 commit comments