-
Notifications
You must be signed in to change notification settings - Fork 4
Observe call events
Federico Marin edited this page Mar 23, 2020
·
13 revisions
To observe a call that has started, has ended or has ended with an error is it necessary to add a call observer to the call module.
To observe the call UI state it is necessary to add a call ui observer to the call module.
CallObserver callObserver = new CallObserver() {
@Override
public void onCallCreated(@NonNull Call call) {
Log.d("Bandyer SDK", "onCallCreated: "
+ call.getCallInfo().getCaller() + ", "
+ TextUtils.join(", ", call.getCallInfo().getCallees()));
}
@Override
public void onCallStarted(@NonNull Call call) {
Log.d("Bandyer SDK", "onCallStarted: "
+ call.getCallInfo().getCaller() + ", "
+ TextUtils.join(", ", call.getCallInfo().getCallees()));
}
@Override
public void onCallEnded(@NonNull Call call) {
Log.d("Bandyer SDK", "onCallEnded: "
+ call.getCallInfo().getCaller() + ", "
+ TextUtils.join(", ", call.getCallInfo().getCallees()));
}
@Override
public void onCallEndedWithError(@NonNull Call call, @NotNull CallException e) {
Log.d("Bandyer SDK", "onCallEndedWithError: "
+ call.getCallInfo().getCaller() + ", "
+ TextUtils.join(", ", call.getCallInfo().getCallees())
+ "\n"
+ "exception: " + e.getMessage());
}
};
CallUIObserver callUIObserver = new CallUIObserver() {
@Override
public void onActivityStarted(@NonNull Call call, @NonNull WeakReference<AppCompatActivity> weakReference) {
Log.d("Bandyer SDK", "onCallActivityStarted: "
+ call.getCallInfo().getCaller() + ", "
+ TextUtils.join(", ", call.getCallInfo().getCallees()));
}
@Override
public void onActivityDestroyed(@NonNull Call call, @NonNull WeakReference<AppCompatActivity> weakReference) {
Log.d("Bandyer SDK", "onCallActivityDestroyed: "
+ call.getCallInfo().getCaller() + ", "
+ TextUtils.join(", ", call.getCallInfo().getCallees()));
}
@Override
public void onActivityError(@NonNull Call call, @NonNull WeakReference<AppCompatActivity> weakReference, @NotNull CallException e) {
Log.d("Bandyer SDK", "onCallActivityError: "
+ call.getCallInfo().getCaller() + ", "
+ TextUtils.join(", ", call.getCallInfo().getCallees())
+ "\n"
+ "exception: " + e.getMessage());
}
};
CallModule callModule = BandyerSDKClient.getInstance().getCallModule();
if (callModule == null) return;
callModule.addCallObserver(callObserver);
// or callModule.addCallObserver(fragmentActivity, callObserver); to automatically dispose the observer on activity destroy.
callModule.addCallUIObserver(callUIObserver);
// or callModule.addCallUIObserver(fragmentActivity, callObserver); to automatically dispose the observer on activity destroy.
If you need to decouple the logic of observing a call it is also provided a way to observe call events through a broadcast receiver as shown below:
Register the call event broadcast receiver in AndroidManifest.xml as shown below:
<!-- Bandyer call event broadcast receiver -->
<application>
<receiver
android:name=".CallEventBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.bandyer.android_sdk.CALL_EVENT_ACTION" />
</intent-filter>
</receiver>
</application>
Add the call event broadcast receiver class to your project:
public class CallEventBroadcastReceiver extends com.bandyer.android_sdk.call.notification.CallEventBroadcastReceiver {
@Override
public void onCallCreated(@NonNull Call call) {
Log.d("Bandyer SDK", "onCallCreated: "
+ call.getCallInfo().getCaller() + ", "
+ TextUtils.join(", ", call.getCallInfo().getCallees()));
}
@Override
public void onCallStarted(@NonNull Call call) {
Log.d("Bandyer SDK", "onCallStarted: "
+ call.getCallInfo().getCaller() + ", "
+ TextUtils.join(", ", call.getCallInfo().getCallees()));
}
@Override
public void onCallEnded(@NonNull Call call) {
Log.d("Bandyer SDK", "onCallEnded: "
+ call.getCallInfo().getCaller() + ", "
+ TextUtils.join(", ", call.getCallInfo().getCallees()));
}
@Override
public void onCallEndedWithError(@NonNull Call call, @NotNull CallException e) {
Log.d("Bandyer SDK", "onCallEndedWithError: "
+ call.getCallInfo().getCaller() + ", "
+ TextUtils.join(", ", call.getCallInfo().getCallees())
+ "\n"
+ "exception: " + e.getMessage());
}
}