@@ -57,34 +57,32 @@ Future<dynamic> myBackgroundMessageHandler(RemoteMessage message) {
5757 });
5858 if (! _callKeepInited) {
5959 _callKeep.setup (
60- null ,
61- < String , dynamic > {
62- 'ios' : {
63- 'appName' : 'CallKeepDemo' ,
64- },
65- 'android' : {
66- 'alertTitle' : 'Permissions required' ,
67- 'alertDescription' :
68- 'This application needs to access your phone accounts' ,
69- 'cancelButton' : 'Cancel' ,
70- 'okButton' : 'ok' ,
71- 'foregroundService' : {
72- 'channelId' : 'com.company.my' ,
73- 'channelName' : 'Foreground service for my app' ,
74- 'notificationTitle' : 'My app is running on background' ,
75- 'notificationIcon' :
76- 'Path to the resource icon of the notification' ,
77- },
60+ showAlertDialog: null ,
61+ options: < String , dynamic > {
62+ 'ios' : {
63+ 'appName' : 'CallKeepDemo' ,
64+ },
65+ 'android' : {
66+ 'additionalPermissions' : [
67+ 'android.permission.CALL_PHONE' ,
68+ 'android.permission.READ_PHONE_NUMBERS'
69+ ],
70+ 'foregroundService' : {
71+ 'channelId' : 'com.example.call-kit-test' ,
72+ 'channelName' : 'callKitTest' ,
73+ 'notificationTitle' : 'My app is running on background' ,
74+ 'notificationIcon' : 'Path to the resource icon of the notification' ,
7875 },
7976 },
80- backgroundMode: true );
77+ },
78+ );
8179 _callKeepInited = true ;
8280 }
8381
8482 logger.d ('backgroundMessage: displayIncomingCall ($callerId )' );
8583 _callKeep.displayIncomingCall (
86- callUUID,
87- callerId,
84+ uuid : callUUID,
85+ handle : callerId,
8886 callerName: callerName,
8987 hasVideo: hasVideo,
9088 );
@@ -220,7 +218,8 @@ class MyAppState extends State<HomePage> {
220218 logger
221219 .d ('[didReceiveStartCallAction] $callUUID , number: ${callData .handle }' );
222220
223- _callKeep.startCall (callUUID, call.number, call.number);
221+ _callKeep.startCall (
222+ uuid: callUUID, handle: call.number, callerName: call.number);
224223
225224 Timer (const Duration (seconds: 1 ), () {
226225 logger.d ('[setCurrentCallActive] $callUUID , number: ${callData .handle }' );
@@ -263,14 +262,14 @@ class MyAppState extends State<HomePage> {
263262 }
264263
265264 Future <void > setOnHold (String callUUID, bool held) async {
266- _callKeep.setOnHold (callUUID, held);
265+ _callKeep.setOnHold (uuid : callUUID, shouldHold : held);
267266 final String handle = calls[callUUID]? .number ?? "No Number" ;
268267 logger.d ('[setOnHold: $held ] $callUUID , number: $handle ' );
269268 setCallHeld (callUUID, held);
270269 }
271270
272271 Future <void > setMutedCall (String callUUID, bool muted) async {
273- _callKeep.setMutedCall (callUUID, muted);
272+ _callKeep.setMutedCall (uuid : callUUID, shouldMute : muted);
274273 final String handle = calls[callUUID]? .number ?? "No Number" ;
275274 logger.d ('[setMutedCall: $muted ] $callUUID , number: $handle ' );
276275 setCallMuted (callUUID, muted);
@@ -280,9 +279,11 @@ class MyAppState extends State<HomePage> {
280279 final String number = calls[callUUID]? .number ?? "No Number" ;
281280 // Workaround because Android doesn't display well displayName, se we have to switch ...
282281 if (isIOS) {
283- _callKeep.updateDisplay (callUUID, callerName: 'New Name' , handle: number);
282+ _callKeep.updateDisplay (
283+ uuid: callUUID, callerName: 'New Name' , handle: number);
284284 } else {
285- _callKeep.updateDisplay (callUUID, callerName: number, handle: 'New Name' );
285+ _callKeep.updateDisplay (
286+ uuid: callUUID, callerName: number, handle: 'New Name' );
286287 }
287288
288289 logger.d ('[updateDisplay: $number ] $callUUID ' );
@@ -302,7 +303,7 @@ class MyAppState extends State<HomePage> {
302303 logger.d ('Display incoming call now' );
303304 final bool hasPhoneAccount = await _callKeep.hasPhoneAccount ();
304305 if (! hasPhoneAccount) {
305- await _callKeep.hasDefaultPhoneAccount (context, < String , dynamic > {
306+ await _callKeep.hasDefaultPhoneAccount (< String , dynamic > {
306307 'alertTitle' : 'Permissions required' ,
307308 'alertDescription' :
308309 'This application needs to access your phone accounts' ,
@@ -318,8 +319,8 @@ class MyAppState extends State<HomePage> {
318319 }
319320
320321 logger.d ('[displayIncomingCall] $callUUID number: $number ' );
321- _callKeep.displayIncomingCall (callUUID, number,
322- handleType: 'number' , hasVideo: false );
322+ _callKeep.displayIncomingCall (
323+ uuid : callUUID, handle : number, handleType: 'number' , hasVideo: false );
323324 }
324325
325326 void didDisplayIncomingCall (CallKeepDidDisplayIncomingCall event) {
@@ -347,29 +348,51 @@ class MyAppState extends State<HomePage> {
347348 _callKeep.on < CallKeepDidPerformDTMFAction > (didPerformDTMFAction);
348349 _callKeep.on < CallKeepDidReceiveStartCallAction > (didReceiveStartCallAction);
349350 _callKeep.on < CallKeepDidToggleHoldAction > (didToggleHoldCallAction);
350- _callKeep.on < CallKeepDidPerformSetMutedCallAction > (didPerformSetMutedCallAction);
351+ _callKeep
352+ .on < CallKeepDidPerformSetMutedCallAction > (didPerformSetMutedCallAction);
351353 _callKeep.on < CallKeepPerformEndCallAction > (endCall);
352354 _callKeep.on < CallKeepPushKitToken > (onPushKitToken);
353355
354- _callKeep.setup (context, < String , dynamic > {
355- 'ios' : {
356- 'appName' : 'CallKeepDemo' ,
357- },
358- 'android' : {
359- 'alertTitle' : 'Permissions required' ,
360- 'alertDescription' :
361- 'This application needs to access your phone accounts' ,
362- 'cancelButton' : 'Cancel' ,
363- 'okButton' : 'ok' ,
364- 'foregroundService' : {
365- 'channelId' : 'com.company.my' ,
366- 'channelName' : 'Foreground service for my app' ,
367- 'notificationId' : 5005 ,
368- 'notificationTitle' : 'My app is running on background' ,
369- 'notificationIcon' : 'Path to the resource icon of the notification' ,
356+ _callKeep.setup (
357+ showAlertDialog: () => showDialog <bool >(
358+ context: context,
359+ barrierDismissible: false ,
360+ builder: (BuildContext context) {
361+ return AlertDialog (
362+ title: const Text ('Permissions Required' ),
363+ content: const Text (
364+ 'This application needs to access your phone accounts' ),
365+ actions: < Widget > [
366+ TextButton (
367+ child: const Text ('Cancel' ),
368+ onPressed: () => Navigator .of (context).pop (false ),
369+ ),
370+ TextButton (
371+ child: const Text ('OK' ),
372+ onPressed: () => Navigator .of (context).pop (true ),
373+ ),
374+ ],
375+ );
376+ },
377+ ).then ((value) => value ?? false ),
378+ options: < String , dynamic > {
379+ 'ios' : {
380+ 'appName' : 'CallKeepDemo' ,
381+ },
382+ 'android' : {
383+ 'additionalPermissions' : [
384+ 'android.permission.CALL_PHONE' ,
385+ 'android.permission.READ_PHONE_NUMBERS'
386+ ],
387+ 'foregroundService' : {
388+ 'channelId' : 'com.example.call-kit-test' ,
389+ 'channelName' : 'callKitTest' ,
390+ 'notificationTitle' : 'My app is running on background' ,
391+ 'notificationIcon' : 'Path to the resource icon of the notification' ,
392+ },
370393 },
371394 },
372- } );
395+ );
373396
374397 if (Platform .isIOS) iOSPermission ();
375398
@@ -394,8 +417,8 @@ class MyAppState extends State<HomePage> {
394417 calls[callUUID] = Call (callerId);
395418 });
396419 _callKeep.displayIncomingCall (
397- callUUID,
398- callerId,
420+ uuid : callUUID,
421+ handle : callerId,
399422 callerName: callerName,
400423 hasVideo: hasVideo,
401424 );
0 commit comments