This is guide to integrate exotel client SDK with flutter.
In this integration ,
-
A flutter compliance Native Android project has been created which will be mediator between flutter and exotel Client SDK.
-
Exotel Client SDK will be imported in flutter compliance Native Android project.
-
This flutter compliant android project is nothing but the translator, which will translate flutter channels message to exotelSDK API invocation and vice versa.
Exotel SDK is integrated as per integration guide (refer section 4.1.2) from exotel-voip-sdk-android repo.
-
Create a MethodChannel and register the channel name, generally using “package name/identity” as the channel name.
-
An asynchronous call is initiated through invokeMethod.
class _SampleAppState extends State<SampleApp> { static const androidChannel = MethodChannel('android/exotel_sdk'); ... void callNativeMethod() async{ ... await androidChannel.invokeMethod('nativeMethod'); ... } ... }
Next, the following functions are implemented in native (android):
-
Create a MethodChannel using the same registration string as the flutter.
-
Implement the nativeMethod.
-
Return the result to flutter through result.
public class MainActivity extends FlutterActivity { private ExotelSDKChannel exotelSDKChannel; @Override public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { GeneratedPluginRegistrant.registerWith(flutterEngine); exotelSDKChannel = new ExotelSDKChannel(flutterEngine,this); exotelSDKChannel.registerMethodChannel(); } }
public class ExotelSDKChannel { private static final String CHANNEL = "android/exotel_sdk"; private MethodChannel channel; public ExotelSDKChannel(FlutterEngine flutterEngine, Context context) { this.flutterEngine = flutterEngine; this.context = context; } void registerMethodChannel() { channel = new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(),CHANNEL); channel.setMethodCallHandler( ((call, result) -> { System.out.println("Entered in Native Android"); switch (call.method) { case "nativeMethod": // write your code result.success("ok"); default: break; } }) ); } }
Please refer VoiceAppService
class of android translator which is
communicate to exotel SDK and implemented as per integration guide from exotel-voip-sdk-android repo.
- android translator then get the subscriber token
- android translator then call initialize method of exotel client SDK with crdentials and subscriber token.
Please refer VoiceAppService
class of android translator which has which has implemented listener events as per integration guide from exotel-voip-sdk-android repo.
-
The code implementation of android calling flutter is similar to that of flutter calling native (android) which via invokeMethod.
public class ExotelSDKChannel { ... public void callFlutterMethod() { channel.invokeMethod("changeUI"); } }
-
The flutter mainly implements the registration of MethodCallHandler:
class _SampleAppState extends State<SampleApp> { static const androidChannel = MethodChannel('android/exotel_sdk'); @override void initState() { super.initState(); androidChannel.setMethodCallHandler(flutterCallHandler); } Future<String> flutterCallHandler(MethodCall call) async { switch (call.method) { case "changeUI": // update UI break; default: break; } return "ok"; } }
- MethodChannel is used for demo / integration purpose. There are other platform channels also also available which can be implemented as per design and use case.
Go to README.md