통화 선택

Android 10(API 수준 29) 이상을 실행하는 기기에서는 앱이 사용자의 주소록에 없는 번호에서 걸려온 전화를 잠재적인 스팸 전화로 식별할 수 있습니다. 사용자는 스팸 전화를 무음으로 거부하도록 선택할 수 있습니다. 사용자가 부재중 전화를 확인할 때 투명성을 높이기 위해 차단된 전화에 관한 정보가 통화 기록에 기록됩니다. Android 10 API를 사용하면 사용자로부터 READ_CALL_LOG 권한을 얻지 않아도 통화 선별 및 발신번호 표시 기능을 제공할 수 있습니다.

CallScreeningService 구현을 사용하여 통화를 선별합니다. 번호가 사용자의 연락처 목록에 없는 경우 수신 또는 발신 전화에 대해 onScreenCall() 함수를 호출합니다. Call.Details 객체에서 통화에 관한 정보를 확인할 수 있습니다. 특히 getCallerNumberVerificationStatus() 함수에는 다른 번호에 관한 네트워크 제공업체의 정보가 포함됩니다. 인증 상태가 실패한 경우 잘못된 번호에서 걸려온 전화이거나 스팸 전화일 가능성이 높습니다.

class ScreeningService : CallScreeningService() {
    // This function is called when an ingoing or outgoing call
    // is from a number not in the user's contacts list
    override fun onScreenCall(callDetails: Call.Details) {
        // Can check the direction of the call
        val isIncoming = callDetails.callDirection == Call.Details.DIRECTION_INCOMING

        if (isIncoming) {
            // the handle (e.g. phone number) that the Call is currently connected to
            val handle: Uri = callDetails.handle

            // determine if you want to allow or reject the call
            when (callDetails.callerNumberVerificationStatus) {
                Connection.VERIFICATION_STATUS_FAILED -> {
                    // Network verification failed, likely an invalid/spam call.
                }
                Connection.VERIFICATION_STATUS_PASSED -> {
                    // Network verification passed, likely a valid call.
                }
                else -> {
                    // Network could not perform verification.
                    // This branch matches Connection.VERIFICATION_STATUS_NOT_VERIFIED.
                }
            }
        }
    }
}

onScreenCall() 함수를 설정하여 respondToCall()를 호출함으로써 새 통화에 응답하는 방법을 시스템에 알립니다. 이 함수는 시스템에 통화를 차단하거나 사용자가 한 것처럼 거부하거나 무음으로 설정하도록 지시하는 데 사용할 수 있는 CallResponse 매개변수를 사용합니다. 또한 이 통화를 기기의 통화 기록에 추가하지 않도록 시스템에 지시할 수도 있습니다.

// Tell the system how to respond to the incoming call
// and if it should notify the user of the call.
val response = CallResponse.Builder()
    // Sets whether the incoming call should be blocked.
    .setDisallowCall(false)
    // Sets whether the incoming call should be rejected as if the user did so manually.
    .setRejectCall(false)
    // Sets whether ringing should be silenced for the incoming call.
    .setSilenceCall(false)
    // Sets whether the incoming call should not be displayed in the call log.
    .setSkipCallLog(false)
    // Sets whether a missed call notification should not be shown for the incoming call.
    .setSkipNotification(false)
    .build()

// Call this function to provide your screening response.
respondToCall(callDetails, response)

시스템이 올바르게 트리거할 수 있도록 적절한 인텐트 필터와 권한을 사용하여 매니페스트 파일에 CallScreeningService 구현을 등록해야 합니다.

<service
    android:name=".ScreeningService"
    android:permission="android.permission.BIND_SCREENING_SERVICE">
    <intent-filter>
        <action android:name="android.telecom.CallScreeningService" />
    </intent-filter>
</service>