Skip to content

Commit

Permalink
Update example to handle android screenshare permissions for API 34+
Browse files Browse the repository at this point in the history
  • Loading branch information
davidliu committed Jul 2, 2024
1 parent f03e0c2 commit 3b67f0d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ room.localParticipant.setScreenShareEnabled(true);

#### Android

On Android, you would have to define a foreground service in your AndroidManifest.xml.
On Android, you will have to use a [media projection foreground service](https://developer.android.com/develop/background-work/services/fg-service-types#media-projection).

In our example, we use the `flutter_background` package to handle this. In the app's AndroidManifest.xml file, declare the service with the appropriate types and permissions as following:

```xml title="AndroidManifest.xml"
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
Expand All @@ -239,6 +241,8 @@ On Android, you would have to define a foreground service in your AndroidManifes
</manifest>
```

Before starting the background service and enabling screen share, you **must** call `Helper.requestCapturePermission()` from `flutter_webrtc`, and only proceed if it returns true.

#### iOS

On iOS, a broadcast extension is needed in order to capture screen content from
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "io.livekit.example"
minSdkVersion 21
targetSdkVersion 31
targetSdkVersion 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
5 changes: 5 additions & 0 deletions example/lib/widgets/controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ class _ControlsWidgetState extends State<ControlsWidget> {
}
if (lkPlatformIs(PlatformType.android)) {
// Android specific
bool hasCapturePermission = await Helper.requestCapturePermission();
if (!hasCapturePermission) {
return;
}

requestBackgroundPermission([bool isRetry = false]) async {
// Required for android screenshare.
try {
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ packages:
dependency: "direct main"
description:
name: flutter_webrtc
sha256: fd5f115a08dcdc00b988bea3003c956f1b60a78a61d899cbddfb44f5d0e44d4a
sha256: a09adf01e8b760a9ca6418323786f51417fb75986f210513e83d4753686795f0
url: "https://pub.dev"
source: hosted
version: "0.10.8"
version: "0.11.1"
glob:
dependency: transitive
description:
Expand Down

0 comments on commit 3b67f0d

Please sign in to comment.