통화 선택

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

CallScreeningService 구현을 사용하여 통화를 선택합니다. 수신 또는 발신 전화의 번호가 사용자의 연락처 목록에 없으면 onScreenCall() 함수를 호출합니다. 호출에 관한 자세한 내용은 Call.Details 객체를 확인하세요. 구체적으로, getCallerNumberVerificationStatus() 함수에는 네트워크 제공업체에서 제공한 다른 번호에 관한 정보가 포함됩니다. 확인에 실패한 경우 잘못된 번호 또는 잠재적인 스팸 전화에서 걸려온 전화입니다.

Kotlin

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.
                }
            }
        }
    }
}

Java

class ScreeningService extends CallScreeningService {
    @Override
    public void onScreenCall(@NonNull Call.Details callDetails) {
        boolean isIncoming = callDetails.getCallDirection() == Call.Details.DIRECTION_INCOMING;

        if (isIncoming) {
            Uri handle = callDetails.getHandle();

            switch (callDetails.getCallerNumberVerificationStatus()) {
                case Connection.VERIFICATION_STATUS_FAILED:
                    // Network verification failed, likely an invalid/spam call.
                    break;
                case Connection.VERIFICATION_STATUS_PASSED:
                    // Network verification passed, likely a valid call.
                    break;
                default:
                    // Network could not perform verification.
                    // This branch matches Connection.VERIFICATION_STATUS_NOT_VERIFIED
            }
        }
    }
}

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

Kotlin

// 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)

Java

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

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

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

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