Push Configuration

Follow the below steps to enable sending push notifications to your users

Consent for Push Notifications:

Starting from Android 13 and above, you need to explicitly ask users for their consent to receive push notifications.

  • Add this permission to your AndroidManifest.xml file:
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
  • If the device uses Android 12 or less, permission to send notifications is already granted. If the device uses Android 13 or above, you need to ask the user for permission.

Use the below code according to the user consent:

import com.contlo.androidsdk.permissions.ContloPermissions
.
.
.
val contloPermissions = ContloPermissions(applicationContext)

//If user grants permission, call this function
contloPermissions.sendPushConsent(applicationContext,true)

//If user denies or revokes the permission, call this function
contloPermissions.sendPushConsent(applicationContext,false)

  • Based upon the consent received, the function would subscribe or unsubscribe your Audience from Mobile Push on your Contlo Dashboard.

Add Contlo’s Push Notification Handler and Click Listener Service:

In your AndroidManifest.xml file, add the following code,

    
<application>
  
  <service
        android:name="com.contlo.androidsdk.push.PushNotifications"
        android:exported="false"
        tools:ignore="Instantiatable">
    
    <intent-filter>
      <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
    
  </service>
  
  <service android:name="com.contlo.androidsdk.push.PushClicked" />
</application

Setting up Mobile Push Credentials:

In your Firebase project, go to Project Settings and click on Service Account tabs, You would see a screen like this:

Clicking on Generate New Private Key will give you a json file with firebase admin SDK credentials. If you already generated one, use it for the next steps otherwise generate a new one.

Then in your Contlo Dashboard, go to settings and click on Mobile Push tab. You would see a screen like this:

Set the credentials according to your json file and save.