Intercept toast messages
Chat UI SDK uses the Android Toast mechanism to display operation results and application state changes. You can implement a global interceptor to customize toast message styling across your application.
Intercept toast messages
The willToast method of ToastInterceptor is called on the UI thread. Return false from the willToast method to intercept the toast.
Java
import ai.nexconn.chatui.utils.common.ToastUtils;
import android.content.Context;
import android.widget.Toast;
import androidx.annotation.NonNull;
ToastUtils.setInterceptor(
new ToastUtils.ToastInterceptor() {
@Override
public boolean willToast(
@NonNull Context context, @NonNull CharSequence text, int duration) {
String s = "This is an intercepted toast: " + text;
Toast.makeText(context, s, Toast.LENGTH_SHORT).show();
return false;
}
});
To remove the interceptor, set it to null.