In-App Messages
In this page you'll learn how in-app messages can be added to your app and what are all the options at your disposal to create a great messaging experience for your users.
These services will bring a new level of contextuality to your app, allowing you to create in-app messages or categorize users based on their interaction behaviour.
As mentioned in the Implementation page, if you are going to use in-app messaging, you must include the following dependency in your app/build.gradle
:
dependencies {
def notificare_version = 'REPLACE_WITH_LATEST_VERSION'
implementation "re.notifica:notificare-in-app-messaging:$notificare_version"
}
Since this is a zero-configuration feature library, you don't have to implement or configure anything other than including the dependency to get started.
Suppressing messages
During certain flows, like during a purchase, it can become convenient to suppress in-app messages from being shown to the user, interrupting their engagement.
You can, optionally, suppress messages by setting a flag. It's important to reset the flag once the priority flow is complete, otherwise the library will continue suppressing the messages until the application is restarted.
Notificare.inAppMessaging().hasMessagesSuppressed = true
NotificareInAppMessagingCompat.setHasMessagesSuppressed(true);
Alternatively, you can exclude certain activities from checking for in-app messages when coming to the foreground.
<activity android:name=".CustomActivity">
<!-- Add this to the activities you want to exclude from the foreground check. -->
<meta-data
android:name="re.notifica.iam.ui.suppress_messages"
android:value="true" />
</activity>
By default, the SDK doesn't re-evaluate the foreground context when you stop suppressing in-app messages. In case you want to trigger a new context evaluation after you stop suppressing in-app messages, you can use the following method instead.
Notificare.inAppMessaging().setMessagesSuppressed(false, evaluateContext = true)
NotificareInAppMessagingCompat.setMessagesSuppressed(false, true);
Messages lifecycle
You can perform additional actions when certain events occur while handling in-app messages. To do so, add a listener as follows:
class MainActivity : AppCompatActivity(), NotificareInAppMessaging.MessageLifecycleListener {
override fun onCreate(savedInstanceState: Bundle?) {
// more code ...
Notificare.inAppMessaging().addLifecycleListener(this)
}
override fun onDestroy() {
// more code ...
Notificare.inAppMessaging().removeLifecycleListener(this)
}
override fun onMessagePresented(message: NotificareInAppMessage) {
}
override fun onMessageFinishedPresenting(message: NotificareInAppMessage) {
}
override fun onMessageFailedToPresent(message: NotificareInAppMessage) {
}
override fun onActionExecuted(message: NotificareInAppMessage, action: NotificareInAppMessage.Action) {
}
override fun onActionFailedToExecute(message: NotificareInAppMessage, action: NotificareInAppMessage.Action, error: Exception?) {
}
}
public class MainActivity extends AppCompatActivity implements NotificareInAppMessaging.MessageLifecycleListener {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
// more code ...
NotificareInAppMessagingCompat.addLifecycleListener(this);
}
@Override
protected void onDestroy() {
// more code ...
NotificareInAppMessagingCompat.removeLifecycleListener(this);
}
@Override
public void onMessagePresented(@NonNull NotificareInAppMessage message) {
}
@Override
public void onMessageFinishedPresenting(@NonNull NotificareInAppMessage message) {
}
@Override
public void onMessageFailedToPresent(@NonNull NotificareInAppMessage message) {
}
@Override
public void onActionExecuted(@NonNull NotificareInAppMessage message, @NonNull NotificareInAppMessage.Action action) {
}
@Override
public void onActionFailedToExecute(@NonNull NotificareInAppMessage message, @NonNull NotificareInAppMessage.Action action, @Nullable Exception error) {
}
}