The Pulsate SDK uses the NotificationCompat.setNumber() API to set the badge count for Android devices. This is the native Android API and shows badges in the default way - for some phones this might be a number, for some it might be a dot, for some custom launchers it might not do anything.

If you want to support more phones and more custom launchers the PulsateSDK returns a callback that informs your App when a push comes or when the badge is changing. Inside that method you can add custom support for more phones / launchers on your own or you can use a 3rd party library like ShortcutBadger to do it for you.

To make sure you get all the badge callbacks make sure you set the badge listener in your Application class in the onCreate callback. If you modify the badge count make sure to return that new badge count in the listener, if you do not modify it make sure to return the original value.

Example implementation:

class PulsateDemoApp : Application() {
    override fun onCreate() {
        super.onCreate()

        val pulsateManager = PulsateFactory.getInstance()

        pulsateManager.setBadgeUpdateListener(object : IPulsateBadgeUpdateListener {
            override fun onBadgeUpdate(badge: Int): Int {
                val newBadgeCount = badge + 100
                ShortcutBadger.applyCount(this@PulsateDemoApp, newBadgeCount)
                return newBadgeCount
            }
        })
    }
}

You can also use "setBadgeUpdateListener" inside a ViewModel to show a custom badge icon inside your App.

class MenuFragmentViewModel constructor() : ViewModel() {
    private val _badgeState: MutableLiveData<Int> = MutableLiveData(0)
    val badgeState: LiveData<Int> get() = _badgeState

    init {
        val pulsateManager = PulsateFactory.getInstance()
        pulsateManager.setBadgeUpdateListener(
            object : IPulsateBadgeUpdateListener {
                override fun onBadgeUpdate(badge: Int): Int {
                    _badgeState.postValue(badge)
                    return badge
                }
            },
        )
    }
}

And in your Activity / Fragment just observe the LiveData from the ViewModel

class MenuFragment : Fragment() {

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mMenuFragmentViewModel.badgeState.observe(viewLifecycleOwner) { badge ->
            mBinding.inboxBtn.text = "INBOX $badge"
        }
    }
    
}