How to hide notification details in lock screen

Solution for How to hide notification details in lock screen
is Given Below:

there is a requirement in my plate to hide notification details in the lock screen programmatically.

There is an option to achieve this by managing notification settings at the android phone level.

general notification be like below
general notification be like below

In phone settings, we have this option to hide notification details on the lock screen.

In phone settings, we have this option to hide notification details on the lock screen.

I got this notification (Excepted output)

after hide details in settings  I got this notification (Excepted output)

I need to achieve this excepted output programmatically.

After my investigation, I found something,
while creating a notification builder, we have a choice to set visibility to the builder

val builder = NotificationCompat.Builder(context!!, selectedChannel).apply {
            setContentTitle(title)
            setContentText(body)
            setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
    setVisibility(NotificationCompat.VISIBILITY_PRIVATE) is a way to get custimization of notification visibility.

It doesn’t fulfill my requirements, need suggestions/ opinions to complete my requirement