TransWikia.com

CallScreeningService - Disconnect call after few seconds - Android 10

Stack Overflow Asked by Rohan Kandwal on November 4, 2021

Trying to disconnect an incoming call after few seconds of ringing on Android 10. Using CallScreeningService for filtering an incoming call.

@RequiresApi(Build.VERSION_CODES.N)
class MyCallScreeningService :
  CallScreeningService() {


  @RequiresApi(Build.VERSION_CODES.Q)
  override fun onScreenCall(details: Call.Details?) {
    if (details?.callDirection == Call.Details.DIRECTION_INCOMING) {
      val phoneNumber = details.handle.schemeSpecificPart
      val blockedList = Paper.book().read(Constants.FIELD_BLOCKED_LIST, ArrayList<String>())
      if (blockedList.contains(phoneNumber)) {
        disconnectCall(details, phoneNumber)
      } 
    }
  }

  private fun disconnectCall(details: Call.Details, phoneNumber: String) {
    Handler().postDelayed({
      respondToCall(details, buildResponse())
    }, 3000L)
  }

  private fun buildResponse(): CallResponse {
    return CallResponse.Builder()
      .setRejectCall(true)
      .setDisallowCall(true)
      .setSkipNotification(true)
      .setSkipCallLog(true)
      .build()
  }
}

Problem is, if I set the handler time too low, the call gets disconnected without ringing on receiver’s side. Although, if I set it higher like 6 secs, then the ringing notification shows, but disconnection doesn’t work.

One Answer

CallScreeningService executes onScreenCall method before the phone rings.

You have 5 seconds to decide either to allow phone to ring or to block the call. If you don't return CallResponse in 5 seconds time, Telephony API will disregard call to your onScreenCall and let the phone ring.

Using CallScreeningService it is not possible to block phone call after few seconds of ringing.

Answered by Gordon Freeman on November 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP