How WhatsApp Shows Incoming Calls on the Android Lock Screen

Understanding FCM, Full-Screen Intents, CallStyle Notifications, and Foreground Services.
You're watching a YouTube video, or perhaps your phone is locked in your pocket. Suddenly, someone calls you on WhatsApp.
Your screen wakes up, and a full-screen incoming call interface appears with Answer and Decline buttons.
Now imagine you're building a similar calling feature in your Android application.
Your backend sends an incoming call event, and you try the obvious approach:
val intent = Intent(
context,
IncomingCallActivity::class.java
)
context.startActivity(intent)Android blocks it.
Since Android 10 (API 29), applications cannot freely launch Activities from the background. This restriction prevents applications from unexpectedly taking over the screen while users are interacting with other applications.
So how do applications like WhatsApp display incoming calls even when their Activity isn't running?
The answer isn't a single API. It's a combination of Android components working together.
Let's understand the complete implementation.
1. Understanding the incoming call flow
There are five important components involved:
High-priority FCM: Delivers the incoming call event.
Full-Screen Intent: Allows Android to launch the call Activity when appropriate.
CallStyle Notification: Provides dedicated Answer and Decline actions.
Lock Screen Activity: Allows the call UI to appear over the lock screen.
Foreground Service: Supports the ongoing call after the user answers.
Here's how they work together:
Backend
|
v
High-Priority FCM
|
v
FirebaseMessagingService
|
v
Create Incoming Call Notification
|
+------ Full-Screen Intent
|
+------ CallStyle Notification
|
v
Android System
|
+------ Phone Locked
| |
| v
| Full-Screen Activity
|
+------ Phone Unlocked
|
v
Heads-Up Notification
|
v
User Answers
|
v
Foreground Service
(phoneCall)The important thing to understand is that your application doesn't directly launch the Activity. Android's notification system decides how the incoming call should be presented.
2. Step 1: Delivering incoming calls using high-priority FCM
Suppose User A calls User B.
Your backend needs to notify User B's device, even if the application isn't currently open.
For this, we use Firebase Cloud Messaging (FCM).
The backend sends a high-priority data message containing the call information:
{
"type": "INCOMING_CALL",
"callId": "call_123",
"callerId": "user_456",
"callerName": "Rahul",
"callType": "VIDEO"
}Firebase invokes your FirebaseMessagingService when the message is delivered.
class MyFirebaseMessagingService :
FirebaseMessagingService() {
override fun onMessageReceived(
message: RemoteMessage
) {
val data = message.data
if (data["type"] == "INCOMING_CALL") {
handleIncomingCall(data)
}
}
}High-priority FCM is useful because it allows time-sensitive, user-visible events to be delivered with higher priority than ordinary background messages.
It can give your application an opportunity to process the event even when its process isn't currently running.
However, remember three things:
High priority doesn't guarantee instant delivery. Network conditions, Doze mode, and device-specific restrictions can affect delivery.
Force-stopped applications cannot rely on receiving FCM messages until the user opens them again.
FCM may deprioritize high-priority messages if they repeatedly don't result in user-visible notifications.
Important: FCM only delivers the incoming call event. It doesn't automatically open your Activity.
For that, we need Full-Screen Intents.
3. Step 2: Full-Screen Intent - The key to displaying incoming calls
Android provides an API called setFullScreenIntent().
It allows you to associate a notification with an Activity that Android can launch when a full-screen presentation is appropriate.
Instead of calling startActivity(), we create a PendingIntent.
val fullScreenPendingIntent =
PendingIntent.getActivity(
context,
100,
Intent(
context,
IncomingCallActivity::class.java
),
PendingIntent.FLAG_UPDATE_CURRENT or
PendingIntent.FLAG_IMMUTABLE
)Now attach it to the notification:
val notification =
NotificationCompat.Builder(
context,
CALL_CHANNEL_ID
)
.setSmallIcon(R.drawable.ic_call)
.setContentTitle("Incoming call")
.setContentText("Rahul is calling...")
.setCategory(NotificationCompat.CATEGORY_CALL)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setFullScreenIntent(
fullScreenPendingIntent,
true
)
.setOngoing(true)
.build()
NotificationManagerCompat
.from(context)
.notify(CALL_NOTIFICATION_ID, notification)Now Android decides how to display the incoming call.
Scenario 1: Phone is locked
Android can launch your full-screen Activity over the lock screen.
Scenario 2: Phone is unlocked
Imagine the user is watching YouTube or browsing Instagram.
Android generally avoids interrupting the current application with a full-screen Activity. Instead, it displays a heads-up notification.
This means your application must support both experiences:
Full-screen incoming call UI.
Incoming call notification with Answer and Decline actions.
The decision belongs to Android's notification system, not your application.
Don't forget notification channels.
Since Android 8.0 (API 26), notification importance is controlled through channels.
For incoming calls, create a channel with high importance:
val channel = NotificationChannel(
CALL_CHANNEL_ID,
"Incoming Calls",
NotificationManager.IMPORTANCE_HIGH
)
notificationManager.createNotificationChannel(channel)The user can subsequently change the channel's importance in Settings.
4. Step 3: CallStyle Notifications (Android 12+)
Have you noticed that incoming call notifications look different from regular notifications?
They display caller information and dedicated Answer and Decline actions.
Android provides a dedicated notification template for this purpose: Notification.CallStyle.
It was introduced in Android 12 (API 31) and is also available through AndroidX using NotificationCompat.CallStyle.
First, create a Person representing the caller:
val caller = Person.Builder()
.setName("Rahul")
.setImportant(true)
.build()Now create the notification:
val notification =
NotificationCompat.Builder(
context,
CALL_CHANNEL_ID
)
.setSmallIcon(R.drawable.ic_call)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setStyle(
NotificationCompat.CallStyle.forIncomingCall(
caller,
declinePendingIntent,
answerPendingIntent
)
)
.setFullScreenIntent(
fullScreenPendingIntent,
true
)
.setOngoing(true)
.build()Notice that we use three different PendingIntents:
Full-Screen: Opens the incoming call screen.
Answer: Accepts the call.
Decline: Rejects the call.
CallStyle gives calling notifications dedicated system presentation and ranking treatment.
One implementation detail worth remembering: a CallStyle notification should be associated with either a full-screen intent or a foreground service to receive its intended call-specific presentation.
5. Step 4: Displaying the Activity over the lock screen
When Android launches your incoming call Activity, we still need to configure it for lock-screen presentation.
Android provides two important APIs: setShowWhenLocked(true)
Allows your Activity to appear over the lock screen. setTurnScreenOn(true)
Allows your Activity to turn on the display when launched.
These are separate behaviours. Here's a simple implementation:
class IncomingCallActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setShowWhenLocked(true)
setTurnScreenOn(true)
setContent {
IncomingCallScreen()
}
}
}You can also configure these properties through the Activity manifest attributes.
Now your Activity can display the incoming call interface over the lock screen.
There's another scenario you must handle: what if the caller cancels the call before the recipient answers?
Your application should cancel the notification and finish the incoming call Activity. You should also implement a call timeout so users don't see outdated incoming call screens.
6. Step 5: Keeping the call alive using a Foreground Service
The user answers the call and presses the Home button to open another application. The calling Activity is no longer visible, but the conversation must continue. This is where a Foreground Service becomes important.
For phone calls, Android provides a specific foreground service type: phoneCall
For applications targeting Android 14 (API 34) and above, foreground service types and their corresponding permissions must be declared.
For example: AndroidManifest.xml
<uses-permission
android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission
android:name="android.permission.FOREGROUND_SERVICE_PHONE_CALL" />
<uses-permission
android:name="android.permission.MANAGE_OWN_CALLS" />
<application>
<service
android:name=".CallForegroundService"
android:exported="false"
android:foregroundServiceType="phoneCall" />
</application>The phoneCall type has an important eligibility requirement.
Your application must either hold MANAGE_OWN_CALLS and satisfy the requirements for a self-managed calling application, or hold the system's default dialer role.
It isn't a generic foreground service type that every application can use simply because it supports VoIP. You can promote the service using:
ServiceCompat.startForeground(
this,
NOTIFICATION_ID,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL
)Remember: a foreground service doesn't keep your Activity alive. They have separate lifecycles.
The service supports the ongoing call, while your application remains responsible for audio handling, connection management, and call lifecycle.
7. Android 14: Full-Screen Intent permission changes
Android 14 introduced stricter rules for full-screen intent access.
For applications targeting API 34 and above, Google Play's default grant is restricted to applications whose core functionality is calling or alarms.
The relevant permission is:
<uses-permission
android:name="android.permission.USE_FULL_SCREEN_INTENT" />However, declaring this permission doesn't guarantee access.
You should check availability at runtime:
val notificationManager =
getSystemService(NotificationManager::class.java)
val canUseFullScreenIntent =
notificationManager.canUseFullScreenIntent()If access isn't available, an eligible application can guide the user to Settings:
if (!notificationManager.canUseFullScreenIntent()) {
val intent = Intent(
Settings.ACTION_MANAGE_APP_USE_FULL_SCREEN_INTENT,
Uri.parse("package:$packageName")
)
startActivity(intent)
}Without full-screen intent access, your application cannot rely on launching the full-screen call interface, and the notification may appear as a heads-up notification instead.
8. Debugging: Why are incoming call notifications delayed?
Imagine your application works perfectly on your device, but some users report that incoming call notifications arrive 15โ20 seconds late.
Where would you start?
I'd investigate these areas:
FCM delivery: Verify that the backend sends a high-priority data message.
Doze mode: Check whether background execution restrictions are affecting delivery.
FCM deprioritization: Check whether previous high-priority messages resulted in visible notifications.
OEM battery restrictions: Some manufacturers introduce additional background execution restrictions.
Message handling: Avoid performing unnecessary network or database operations before posting the notification.
Notification configuration: Verify notification permission, channel importance, full-screen intent access, and successful notification posting.
Log timestamps at every stage:
Backend sends FCM
|
v
FCM receives message
|
v
onMessageReceived()
|
v
Notification posted
|
v
Notification displayedThis helps identify exactly where the delay occurs instead of randomly changing battery optimization settings.
Interview Questions Based on This Scenario
In a senior Android interview, understanding API definitions isn't enough. Interviewers often explore how different components interact.
Here are eight follow-up questions I'd ask:
Why can't you simply call
startActivity()from FirebaseMessagingService?What happens when an incoming call arrives while the user is watching YouTube?
What's the difference between a regular notification and a CallStyle notification?
Why do we need both
setShowWhenLocked()andsetTurnScreenOn()?What happens if
USE_FULL_SCREEN_INTENTisn't granted on Android 14?What breaks if you forget to declare the
phoneCallforeground service type?Does high-priority FCM guarantee immediate delivery?
How would you handle an incoming VoIP call when a cellular call is already active?
These questions test whether you understand the complete system behaviour, not just individual Android APIs.
A full-screen incoming call isn't achieved through a single Android API.
It's a combination of components working together:
FCM delivers the incoming call event.
Full-Screen Intent allows Android to launch the call Activity when appropriate.
CallStyle provides a dedicated calling notification experience.
showWhenLocked() and turnScreenOn() configure the Activity for lock-screen presentation.
Foreground Service supports the ongoing call after the user answers.
The most important concept is that Android remains in control of when and how your Activity is presented.
Knowing an API is one thing. Understanding why it exists, how it interacts with other components, and what happens when something goes wrong is what makes you a stronger Android engineer.
Preparing for Your Next Android Career Move?
After mentoring 600+ Android developers and conducting 200+ mock interviews, I've noticed a recurring pattern.
Many experienced developers understand Kotlin, Jetpack Compose, Coroutines, and the Android framework. But when interviewers introduce real-world scenarios and start asking follow-up questions, things become challenging.
That's exactly what I focus on in my Android Job Ready Bootcamp.
It's designed for Android developers with 3โ12 years of experience who want to switch jobs and prepare for opportunities at top product companies.
Over the next few months, we'll work on Android internals, real-world scenarios, Kotlin, Coroutines, Compose, Mobile System Design, machine coding, and mock interviews.
The objective isn't just to cover more topics. It's to develop the technical depth and confidence required to handle challenging senior Android interviews.
Comments (0)
No comments yet. Be the first to share your thoughts!
Leave a Comment
Get the latest updates
Join our newsletter and never miss an article.