Skip to content

Upgrade to Bandyer SDK v1.5.x

Kristiyan Petrov edited this page Apr 6, 2021 · 7 revisions

This new version comes with general improvements, new ways to observe ongoing calls and chats and comes with APIs that have been simplified to let the SDK integration be easier for third part apps.


Observe call events

The CallObserver has been refactored to decouple UI and communication events.

For this reason a new call UI observer has been added and can be used to observe the call activity state as shown below.

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,
                                @NonNull 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.addCallUIObserver(callUIObserver);
// or callModule.addCallUIObserver(fragmentActivity, callObserver);
// to automatically dispose the observer on activity destroy.  

The call observer has been improved with new callbacks and a call info object shipped through the Call object. With the following observer you will receive the call events without considering the UI lifecycle.

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,
                                     @NonNull CallException e) {
         Log.d("Bandyer SDK", "onCallEndedWithError: "
               + 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.   

Additional Notes

If you need to decouple the logic of observing a call, the call observer is also provided via broadcast receiver as shown here.

Observe Chat Events

The current ChatObserver methods have been deprecated because they are strongly coupled with the UI lifecycle. Instead of the ChatObserver it's recommended to use the new chat UI observer which can be used to observe the chat activity state as shown below.

ChatUIObserver chatUIObserver = new ChatUIObserver() {

    @Override
    public void onActivityStarted(@NonNull Chat chat,
                                  @NonNull WeakReference<AppCompatActivity> activity) {
         Log.d("Bandyer SDK", "onChatActivityStarted");
    }
        
    @Override
    public void onActivityDestroyed(@NonNull Chat chat,
                                    @NonNull WeakReference<AppCompatActivity> activity) {
         Log.d("Bandyer SDK", "onChatActivityDestroyed");
    }

    @Override
    public void onActivityError(@NonNull Chat chat,
                                @NonNull WeakReference<AppCompatActivity> activity,
                                @NonNull ChatException error) {
         Log.e("Bandyer SDK", "onChatActivityError " + error.getMessage());
    }
};

ChatModule chatModule = BandyerSDKClient.getInstance().getChatModule();
if (chatModule == null) return;

chatModule.addChatUIObserver(chatUIObserver);
// or chatModule.addChatUIObserver(fragmentActivity, chatObserver);
// to automatically dispose the observer on activity destroy.     

Additional notes

  • The old ChatObserver methods have been deprecated and new ones will be avaialble in the future which will represent the lifecycle of a chat without considering the UI.
  • The old ChatObserver events are also forwarded via broadcast receiver as shown here.

Notification listeners

Notification listeners has now been simplified removing the method:

@Override 
public void onNotificationAction(@NonNull final NotificationAction action {
     // Here you can execute your own code before executing the default action of the notification
     action.execute();
}

Notification actions will be automatically executed, but it is still possible to prevent that a notification is shown not invoking show methods in onIncomingCall, onIncomingChat and onIncomingFile methods.

Incoming chats

Incoming chat in the ChatNotificationListener can now be shown as notification or as activities as shown below:

@Override
public void onIncomingChat(@NonNull IncomingChat chat,
                           boolean isDnd,
                           boolean isScreenLocked) {
     CallCapabilities callCapabilities = getDefaultCallCapabilities();
     // You may also initialize the callOptions without any argument in the constructor
     // You can enable a single option using the utility methods
     // Example :
     // new CallOptions().withBackCameraAsDefault();

     CallOptions callOptions = new CallOptions(
                        DefaultCallSettingsManager.isCallRecordingEnabled(App.this),
                        DefaultCallSettingsManager.isBackCameraAsDefaultEnabled(App.this),
                        DefaultCallSettingsManager.isProximitySensorDisabled(App.this));

     chat.withAudioCallCapability(callCapabilities, callOptions)
         .withAudioUpgradableCallCapability(callCapabilities, callOptions)
         .withAudioVideoCallCapability(callCapabilities, callOptions);

     chat.asNotification().show(App.this);
}

Other call functions that needs to be migrated

The resumeCallActivity() method in the BandyerSDKClient has now been removed and replaced with the following method:

CallModule callModule = BandyerSDKClient.getInstance().getCallModule();
if (callModule == null) return;

Call ongoingCall = callModule.getOngoingCall();
if (ongoingCall == null) return;

callModule.setDisplayMode(ongoingCall, CallDisplayMode.FOREGROUND);

For more details and other display modes please refer to this wiki page.

User Contact Provider

User contact provider has now been renamed and refactored as shown below:

BandyerSDK.Builder builder = new BandyerSDK.Builder(appContext, appId)

builder.withUserDetailsProvider(new UserDetailsProvider() {

    @Override
    public void onUserDetailsRequested(@NonNull final List<String> userAliases,
                                       @NonNull final OnUserDetailsListener onDetailsListener) {
		
         ArrayList<UserDetails> details = new ArrayList<>();
                       
         // fetch asynchronously data on your local or network storage for each user alias 
                        
         for(String userAlias : userAliases) {
                  details.add(new UserDetails.Builder(userAlias)
					.withNickName("nickname")
					.withFirstName("name")
					.withLastName("last name")
					.withEmail("email")
					.withImageUrl("url") // or .withImageUri(uri) or .withResId(resId)
					.build());
         }
                        
         // provide results to the OnUserDetailsListener object
         onDetailsListener.provide(details);
    }
});

A caching version of User Details Provider is now shipped with the SDK. The CachedUserDetailsProvider extends the UserDetails Provider and will cache at runtime previous request preventing the integrating app's logic be called again with same parameters.

For additional details please refer to this wiki page.

Broadcast unahandled receiver changed

Unhandled Exception Broadcast has been refactored simplifing exception unmarshalling from intent's bundle.

The broadcast receiver should now be registered in the manifest as shown below:

 <!-- Bandyer unhandled broadcast receiver -->

<application>

        <receiver
            android:name=".exceptions.BandyerExceptionReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="com.bandyer.android_sdk.BANDYER_UNHANDLED_EXCEPTION" />
            </intent-filter>
        </receiver>

</application>

Change your current broadcast receiver to extend the BandyerUnhandledExceptionBroadcastReceiver class and override new onException(Throwable error) method as shown below:

public class BandyerExceptionReceiver extends BandyerUnhandledExceptionBroadcastReceiver {

    static final String TAG = "BANDYER SDK EXCEPTION";

    @Override
    public void onException(@NonNull Throwable error) {
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        error.printStackTrace(printWriter);

        Log.e(TAG, stringWriter.toString());
    }
}

For additional details please refer to this wiki page.

Other changes

  • Bandyer Android SDK supports now TLS 1.2+ connections trought Bandyer's servers.
  • Added method to broadcast a successful user identity verification during a call. For further information please refer to this wiki page.

Complete changes overview

v1.5.0

Clone this wiki locally