8000 Fix for Issue #409, including updating example project to run on Andr… · tmthecoder/flutter-webrtc@8bc8fbf · GitHub
[go: up one dir, main page]

Skip to content

Commit 8bc8fbf

Browse files
admarwickAlan Marwick
and
Alan Marwick
authored
Fix for Issue flutter-webrtc#409, including updating example project to run on Android 10. (flutter-webrtc#410)
* Fixes [Issue flutter-webrtc#409](flutter-webrtc#409), and updates the example to run on Android 10. - Fix [Issue flutter-webrtc#409](flutter-webrtc#409) by adding a null guard to `com.cloudwebrtc.webrtc/MedhodCallHandler.java`, case "startRecordToFile". - Update the example project with the ForegroundService needed to run it on Android 10. * fixup! Fixes [Issue flutter-webrtc#409](flutter-webrtc#409), and updates the example to run on Android 10. * fixup! Fixes [Issue flutter-webrtc#409](flutter-webrtc#409), and updates the example to run on Android 10. Co-authored-by: Alan Marwick <admarwick@gmail.com>
1 parent 0c1b13a commit 8bc8fbf

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

android/src/main/java/com/cloudwebrtc/webrtc/MethodCallHandlerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,8 @@ public void onMethodCall(MethodCall call, @NonNull Result notSafeResult) {
482482
}
483483
}
484484
AudioChannel audioChannel = null;
485-
if (call.hasArgument("audioChannel")) {
485+
if (call.hasArgument("audioChannel")
486+
&& call.argument("audioChannel") != null) {
486487
audioChannel = AudioChannel.values()[(Integer) call.argument("audioChannel")];
487488
}
488489
Integer recorderId = call.argument("recorderId");

example/lib/main.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import 'dart:core';
2+
import 'dart:io';
23

34
import 'package:flutter/foundation.dart'
45
show debugDefaultTargetPlatformOverride;
56
import 'package:flutter/material.dart';
7+
import 'package:flutter_foreground_plugin/flutter_foreground_plugin.dart';
68
import 'package:flutter_webrtc/flutter_webrtc.dart';
79

810
import 'src/data_channel_sample.dart';
@@ -15,10 +17,35 @@ import 'src/route_item.dart';
1517
void main() {
1618
if (WebRTC.platformIsDesktop) {
1719
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
20+
} else if(Platform.isAndroid) {
21+
WidgetsFlutterBinding.ensureInitialized();
22+
startForegroundService();
1823
}
1924
runApp(MyApp());
2025
}
2126

27+
startForegroundService() async {
28+
await FlutterForegroundPlugin.setServiceMethodInterval(seconds: 5);
29+
await FlutterForegroundPlugin.setServiceMethod(globalForegroundService);
30+
await FlutterForegroundPlugin.startForegroundService(
31+
holdWakeLock: false,
32+
onStarted: () {
33+
print("Foreground on Started");
34+
},
35+
onStopped: () {
36+
print("Foreground on Stopped");
37+
},
38+
title: "Tcamera",
39+
content: "Tcamera sharing your screen.",
40+
iconName: "ic_stat_mobile_screen_share",
41+
);
42+
return true;
43+
}
44+
45+
void globalForegroundService() {
46+
debugPrint("current datetime is ${DateTime.now()}");
47+
}
48+
2249
class MyApp extends StatefulWidget {
2350
@override
2451
_MyAppState createState() => _MyAppState();

example/pubspec.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ dependencies:
1010
# Use with the CupertinoIcons class for iOS style icons.
1111
cupertino_icons: ^1.0.0
1212

13+
flutter_foreground_plugin: ^0.5.0
14+
15+
1316
flutter_webrtc:
1417
path: ../
1518

example/scripts/project_tools.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function add_permission_label() {
4545
python add-line.py -i ../android/app/src/main/AndroidManifest.xml -s "<application" -t ' <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />'
4646
python add-line.py -i ../android/app/src/main/AndroidManifest.xml -s "<application" -t ' <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />'
4747
python add-line.py -i ../android/app/src/main/AndroidManifest.xml -s "<application" -t ' <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />'
48+
python add-line.py -i ../android/app/src/main/AndroidManifest.xml -s "<application" -t ' <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />'
4849
echo ""
4950
echo "Add permission labels to macOS."
5051
echo ""

0 commit comments

Comments
 (0)
0