2

Background

I'm investigating how to replace the UI of the dialer, when the user gets a phone call (incoming/outgoing phone calls).

This seems to be possible in 2 ways:

  • On old Android versions, it's possible by having an on top view that is triggered by PHONE_STATE_CHANGED and NEW_OUTGOING_CALL Intents.

  • On new Android versions (at least API 23 - Android M-6.0) , it's possible by extending InCallService, and provide an Activity that will be opened from there. I've even found an example to do it, here.

The problem

Looking at how the built in dialer works, if the user is using an app in immersive mode (a game or a YouTube video on landscape), and now the device is ringing (incoming call), there is a notification instead of a full screen Activity.

But I can't find how to do it using the API.

What I've tried

I've tried to look at all the docs of InCallService. I've also tried to see if I can differentiate between immersive and non-immersive, by checking the various values I get from WindowManager:

    val wm = getSystemService(Service.WINDOW_SERVICE) as WindowManager
    val display = wm.defaultDisplay
    val metrics = DisplayMetrics()
    display.getMetrics(metrics)
    val realMetrics = DisplayMetrics()
    display.getRealMetrics(realMetrics)
    val realSize = Point()
    display.getRealSize(realSize)
    val size = Point()
    display.getSize(size)
    Log.d("AppLog", "mode:${display.mode} state:${display.state} size:$size realSize:$realSize metrics:$metrics realMetrics:$realMetrics rotation:${display.rotation}")

I guess it might be possible to check it using accessibility service (not sure how though), but this seems like too much to do for it.

The question

Is it possible for the app to check if the screen is now in immersive mode?

If it is possible, how, and from which Android version is it supported?

If it's not possible, how come the built in app knows how to check it?

android developer
  • 114,585
  • 152
  • 739
  • 1,270

1 Answers1

1

You should post your incoming call as a Notification.

In your notification builder, use a Pending intent to launch the full-screen version of your incoming call UI: builder.setContentIntent(pendingIntent); builder.setFullScreenIntent(pendingIntent, true);

The system will show the heads up notification if there is any ongoing activity (and it should take into account immersive mode). If the user's device is off and on the lock screen, the full screen intent would be used to launch a full-screen UI.

TGunn
  • 169
  • 3
  • That's correct, but I was sure there is a difference between whether you are on immersive app and normal app. The built in phone app shows a notification for both of those cases. Only if the user is on the lock screen (or screen is turned off), the built-in phone app is shown in full screen. Is there a way to differentiate between immersive and non-immersive apps? Maybe for immersive apps I could be even more subtle? – android developer Jul 04 '18 at 08:45