It's possible to merge a phone call with flutter?

207 Views Asked by At

I would like to know if it is possible, during a phone call, to merge the current call with another call made from an app developed with Flutter?

During a phone call, I want to be able to add another call, from my app, and merge both calls automatically.

I've been unable to find a flutter package with telephony control.

Regards

1

There are 1 best solutions below

0
Freeman On

I think for iOS, better to use the CallKit framework to handle call management and in Android, better to use the Android TelephonyManager and Call APIs to control phone calls programmatically, so let me show you with an example, but be aware this is just a basic example to demonstrate the concept of call merging!!!

in iOS and in Objective-C

#import <CallKit/CallKit.h>

@interface CallMergeManager : NSObject
@property (nonatomic, strong) CXCallController *callController;
@end

@implementation CallMergeManager

- (instancetype)init {
    self = [super init];
    if (self) {
        _callController = [[CXCallController alloc] init];
    }
    return self;
}

- (void)mergeCalls {
    CXSetMutedCallAction *mergeAction = [[CXSetMutedCallAction alloc] initWithCallUUID:[NSUUID UUID] muted:NO];
    CXTransaction *transaction = [[CXTransaction alloc] initWithAction:mergeAction];
    [self.callController requestTransaction:transaction completion:^(NSError * _Nullable error) {
        if (error) {
            NSLog(@"merging calls error: %@", error);
        }
    }];
}

@end

and in Android with java, something like this :

public class CallMergeManager {
    private TelephonyManager telephonyManager;

    public CallMergeManager(Context context) {
        telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    }

    public void mergeCalls() {
        telephonyManager.mergeCalls();
    }
}

now, in Flutter, you can define a platform channel to communicate with the native code like below for both of them (iOS and Android)

import 'package:flutter/services.dart';

final MethodChannel _channel = MethodChannel('call_merge_channel');

Future<void> mergeCalls() async {
  try {
    await _channel.invokeMethod('mergeCalls');
  } catch (e) {
    print('merging calls error: $e');
  }
}

and for invoking the mergeCalls from Flutter to trigger call merging:

mergeCalls();

Good luck!