[Android] fix screen sharing crash on first boot (#203)

* fix screen sharing crash on first boot.

* update.

* update.

* Update controls.dart
This commit is contained in:
CloudWebRTC
2023-02-03 14:59:49 +08:00
committed by GitHub
parent 8d911b1059
commit 5d727bee5d
+19 -4
View File
@@ -156,21 +156,36 @@ class _ControlsWidgetState extends State<ControlsWidget> {
} }
if (WebRTC.platformIsAndroid) { if (WebRTC.platformIsAndroid) {
// Android specific // Android specific
try { requestBackgroundPermission([bool isRetry = false]) async {
// Required for android screenshare. // Required for android screenshare.
try {
bool hasPermissions = await FlutterBackground.hasPermissions;
if (!isRetry) {
const androidConfig = FlutterBackgroundAndroidConfig( const androidConfig = FlutterBackgroundAndroidConfig(
notificationTitle: 'Screen Sharing', notificationTitle: 'Screen Sharing',
notificationText: 'LiveKit Example is sharing the screen.', notificationText: 'LiveKit Example is sharing the screen.',
notificationImportance: AndroidNotificationImportance.Default, notificationImportance: AndroidNotificationImportance.Default,
notificationIcon: notificationIcon: AndroidResource(
AndroidResource(name: 'livekit_ic_launcher', defType: 'mipmap'), name: 'livekit_ic_launcher', defType: 'mipmap'),
); );
await FlutterBackground.initialize(androidConfig: androidConfig); hasPermissions = await FlutterBackground.initialize(
androidConfig: androidConfig);
}
if (hasPermissions &&
!FlutterBackground.isBackgroundExecutionEnabled) {
await FlutterBackground.enableBackgroundExecution(); await FlutterBackground.enableBackgroundExecution();
}
} catch (e) { } catch (e) {
if (!isRetry) {
return await Future<void>.delayed(const Duration(seconds: 1),
() => requestBackgroundPermission(true));
}
print('could not publish video: $e'); print('could not publish video: $e');
} }
} }
await requestBackgroundPermission();
}
if (WebRTC.platformIsIOS) { if (WebRTC.platformIsIOS) {
var track = await LocalVideoTrack.createScreenShareTrack( var track = await LocalVideoTrack.createScreenShareTrack(
const ScreenShareCaptureOptions( const ScreenShareCaptureOptions(