In Android, make Caller ID notification visually appear on screen when there is incoming call?

592 views Asked by At

We are working on an app which can recognize the name of the incoming call from the phone number. (Our problem is similar to this one but the solution is different) We have created a CallScreeningService which receives the phone number of the incoming phone call and we are able to display the toast showing the caller id whenever there is a call. However, instead of displaying a toast we want to display a notification. (We had also tried displaying a pop up window over Android native incoming call screen like true caller Android app but failed to show it when app is in background or closed state) Now we are also able to create a notification of caller ID whenever there is a call but it is not visually appearing on the screen.

Is it possible to make the notification visually appear on the screen at the same time as an incoming phone call? If yes, how?

Thank you so much!

1

There are 1 answers

0
Rastko Stamenkovic On

Assuming you found a way to keep your app alive in doze mode you need to set your Notification's Channel importance or notification's priority to high or max(side note: Notification channel's importance overrides Notification builder's priority).

NotificationChannel:

NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_HIGH);

Notification builder:

NotificationCompat.Builder mBuilder =
            (NotificationCompat.Builder) new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.some_small_icon)
            .setContentTitle("Title")
            .setContentText("This is a test notification with MAX priority")
            .setPriority(Notification.PRIORITY_MAX);

If doze mode is killing your app, you can use foreground service with return Service.START_STICKY; or WakefulBroadcastReceiver mixed with startWakefulService().