[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
+27 -12
View File
@@ -156,20 +156,35 @@ 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.
const androidConfig = FlutterBackgroundAndroidConfig( try {
notificationTitle: 'Screen Sharing', bool hasPermissions = await FlutterBackground.hasPermissions;
notificationText: 'LiveKit Example is sharing the screen.', if (!isRetry) {
notificationImportance: AndroidNotificationImportance.Default, const androidConfig = FlutterBackgroundAndroidConfig(
notificationIcon: notificationTitle: 'Screen Sharing',
AndroidResource(name: 'livekit_ic_launcher', defType: 'mipmap'), notificationText: 'LiveKit Example is sharing the screen.',
); notificationImportance: AndroidNotificationImportance.Default,
await FlutterBackground.initialize(androidConfig: androidConfig); notificationIcon: AndroidResource(
await FlutterBackground.enableBackgroundExecution(); name: 'livekit_ic_launcher', defType: 'mipmap'),
} catch (e) { );
print('could not publish video: $e'); hasPermissions = await FlutterBackground.initialize(
androidConfig: androidConfig);
}
if (hasPermissions &&
!FlutterBackground.isBackgroundExecutionEnabled) {
await FlutterBackground.enableBackgroundExecution();
}
} catch (e) {
if (!isRetry) {
return await Future<void>.delayed(const Duration(seconds: 1),
() => requestBackgroundPermission(true));
}
print('could not publish video: $e');
}
} }
await requestBackgroundPermission();
} }
if (WebRTC.platformIsIOS) { if (WebRTC.platformIsIOS) {
var track = await LocalVideoTrack.createScreenShareTrack( var track = await LocalVideoTrack.createScreenShareTrack(