A
A
Alexander2022-01-19 13:21:40
Android
Alexander, 2022-01-19 13:21:40

Implementation of dialer functionality as in Telegram, Skype, Viber ....?

I am writing an application in which there should be call functionality similar to Telegram, Skype, Viber. Webrtc was chosen for implementation, there are no problems with this, everything works. The problem is how to implement the incoming call functionality directly. Unfortunately, I could not find any information on how to do this, I found only examples of which a notification is simply displayed. But this option does not suit me, it is necessary that when calling, the melody that is installed on the device for calls plays, besides, the notification is hidden a few seconds after the display.
Maybe someone can share a link to an article that describes the implementation of such functionality, or at least tell you which way to look.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2022-02-01
@fuliozor

The sound of the call and vibration must be played by yourself.
To display the notification, you need to set the maximum priority for NotificationChannel, it is also worth turning off sounds and vibration so that the notification sound does not overlap with the call sound

val channel = NotificationChannel(CALLS_CHANNEL_ID, name, NotificationManager.IMPORTANCE_HIGH)
channel.lockscreenVisibility = NotificationCompat.VISIBILITY_PUBLIC
channel.enableLights(false)
channel.enableVibration(false)
channel.setSound(null, null)

It is also necessary to set the CATEGORY_CALL category for the notification and set the FullScreenIntent
. It turned out like this for me:
val notificationBuilder = NotificationCompat.Builder(context, CALLS_CHANNEL_ID)
            .setSmallIcon(R.mipmap.logo)
            .setContentTitle(title)
            .addAction(
                answerButtonIcon,
                answerButtonText,
                answerPendingIntent
            )
            .addAction(
                decineButtonIcon,
                declineButtonText,
                declinePendingIntent
            )
            .setSound(null)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setPriority(NotificationCompat.PRIORITY_MAX)
            .setCategory(NotificationCompat.CATEGORY_CALL)
            .setCustomBigContentView(customContentView)
            .setCustomHeadsUpContentView(customContentView)
            .setShowWhen(false)
            .setFullScreenIntent(
                PendingIntent.getActivity(
                    context,
                    12345,
                    callActivityIntent,
                    PendingIntentUtil.flags(0)
                ), true
            )
            .setDeleteIntent(declinePendingIntent)

Basically, that's all. More details can be found in the telegram sources .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question