Widget Configuration
Intercept Widgets
Widgets can be intercepted to add a Toast before showing the widget or delaying them until the user approve to see them.
-
Create a WidgetInterceptor
-
widgetWantsToShow() will be called by the SDK when a widget is ready to be shown on screen.
-
At this time Call
ShowWidget()
to show the widget ordismissWidget()
to dismiss it.
// Example of Widget Interceptor showing a dialog
private val interceptor = object : WidgetInterceptor() {
override fun widgetWantsToShow() {
AlertDialog.Builder(context).apply {
setMessage("You received a Widget, what do you want to do?")
setPositiveButton("Show") { _, _ ->
showWidget() // Releases the widget
}
setNegativeButton("Dismiss") { _, _ ->
dismissWidget() // Discards the widget
}
create()
}.show()
}
}
// You just need to add it on your session instance
session.widgetInterceptor = interceptor
// Example of Widget Interceptor showing a dialog
WidgetInterceptor interceptor = new WidgetInterceptor() {
@Override
public void widgetWantsToShow(@NotNull LiveLikeWidgetEntity widgetData) {
new AlertDialog.Builder(context)
.setMessage("You received a Widget, what do you want to do?")
.setPositiveButton("Show", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showWidget(); // Releases the widget
}
})
.setNegativeButton("Dismiss", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dismissWidget(); // Discards the widget
}
})
.create()
.show();
}
};
// You just need to add it on your session instance
session.setWidgetInterceptor(interceptor);
Updated about 1 year ago