@@ -57,34 +57,32 @@ Future<dynamic> myBackgroundMessageHandler(RemoteMessage message) {
57
57
});
58
58
if (! _callKeepInited) {
59
59
_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' ,
78
75
},
79
76
},
80
- backgroundMode: true );
77
+ },
78
+ );
81
79
_callKeepInited = true ;
82
80
}
83
81
84
82
logger.d ('backgroundMessage: displayIncomingCall ($callerId )' );
85
83
_callKeep.displayIncomingCall (
86
- callUUID,
87
- callerId,
84
+ uuid : callUUID,
85
+ handle : callerId,
88
86
callerName: callerName,
89
87
hasVideo: hasVideo,
90
88
);
@@ -220,7 +218,8 @@ class MyAppState extends State<HomePage> {
220
218
logger
221
219
.d ('[didReceiveStartCallAction] $callUUID , number: ${callData .handle }' );
222
220
223
- _callKeep.startCall (callUUID, call.number, call.number);
221
+ _callKeep.startCall (
222
+ uuid: callUUID, handle: call.number, callerName: call.number);
224
223
225
224
Timer (const Duration (seconds: 1 ), () {
226
225
logger.d ('[setCurrentCallActive] $callUUID , number: ${callData .handle }' );
@@ -263,14 +262,14 @@ class MyAppState extends State<HomePage> {
263
262
}
264
263
265
264
Future <void > setOnHold (String callUUID, bool held) async {
266
- _callKeep.setOnHold (callUUID, held);
265
+ _callKeep.setOnHold (uuid : callUUID, shouldHold : held);
267
266
final String handle = calls[callUUID]? .number ?? "No Number" ;
268
267
logger.d ('[setOnHold: $held ] $callUUID , number: $handle ' );
269
268
setCallHeld (callUUID, held);
270
269
}
271
270
272
271
Future <void > setMutedCall (String callUUID, bool muted) async {
273
- _callKeep.setMutedCall (callUUID, muted);
272
+ _callKeep.setMutedCall (uuid : callUUID, shouldMute : muted);
274
273
final String handle = calls[callUUID]? .number ?? "No Number" ;
275
274
logger.d ('[setMutedCall: $muted ] $callUUID , number: $handle ' );
276
275
setCallMuted (callUUID, muted);
@@ -280,9 +279,11 @@ class MyAppState extends State<HomePage> {
280
279
final String number = calls[callUUID]? .number ?? "No Number" ;
281
280
// Workaround because Android doesn't display well displayName, se we have to switch ...
282
281
if (isIOS) {
283
- _callKeep.updateDisplay (callUUID, callerName: 'New Name' , handle: number);
282
+ _callKeep.updateDisplay (
283
+ uuid: callUUID, callerName: 'New Name' , handle: number);
284
284
} else {
285
- _callKeep.updateDisplay (callUUID, callerName: number, handle: 'New Name' );
285
+ _callKeep.updateDisplay (
286
+ uuid: callUUID, callerName: number, handle: 'New Name' );
286
287
}
287
288
288
289
logger.d ('[updateDisplay: $number ] $callUUID ' );
@@ -302,7 +303,7 @@ class MyAppState extends State<HomePage> {
302
303
logger.d ('Display incoming call now' );
303
304
final bool hasPhoneAccount = await _callKeep.hasPhoneAccount ();
304
305
if (! hasPhoneAccount) {
305
- await _callKeep.hasDefaultPhoneAccount (context, < String , dynamic > {
306
+ await _callKeep.hasDefaultPhoneAccount (< String , dynamic > {
306
307
'alertTitle' : 'Permissions required' ,
307
308
'alertDescription' :
308
309
'This application needs to access your phone accounts' ,
@@ -318,8 +319,8 @@ class MyAppState extends State<HomePage> {
318
319
}
319
320
320
321
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 );
323
324
}
324
325
325
326
void didDisplayIncomingCall (CallKeepDidDisplayIncomingCall event) {
@@ -347,29 +348,51 @@ class MyAppState extends State<HomePage> {
347
348
_callKeep.on < CallKeepDidPerformDTMFAction > (didPerformDTMFAction);
348
349
_callKeep.on < CallKeepDidReceiveStartCallAction > (didReceiveStartCallAction);
349
350
_callKeep.on < CallKeepDidToggleHoldAction > (didToggleHoldCallAction);
350
- _callKeep.on < CallKeepDidPerformSetMutedCallAction > (didPerformSetMutedCallAction);
351
+ _callKeep
352
+ .on < CallKeepDidPerformSetMutedCallAction > (didPerformSetMutedCallAction);
351
353
_callKeep.on < CallKeepPerformEndCallAction > (endCall);
352
354
_callKeep.on < CallKeepPushKitToken > (onPushKitToken);
353
355
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
+ },
370
393
},
371
394
},
372
- } );
395
+ );
373
396
374
397
if (Platform .isIOS) iOSPermission ();
375
398
@@ -394,8 +417,8 @@ class MyAppState extends State<HomePage> {
394
417
calls[callUUID] = Call (callerId);
395
418
});
396
419
_callKeep.displayIncomingCall (
397
- callUUID,
398
- callerId,
420
+ uuid : callUUID,
421
+ handle : callerId,
399
422
callerName: callerName,
400
423
hasVideo: hasVideo,
401
424
);
0 commit comments