Sesli aramaları süz

Android 10 (API düzeyi 29) veya sonraki sürümleri çalıştıran cihazlar, uygulamanızın kullanıcının adres defterinde olmayan numaralardan gelen aramaları olası spam aramalar olarak tanımlamasına izin verir. Kullanıcılar spam aramaların sessizce reddedilmesini seçebilir. Kullanıcılara cevapsız arama geldiğinde daha fazla şeffaflık sağlamak için bu engellenen aramalarla ilgili bilgiler çağrı kaydına kaydedilir. Android 10 API kullanıldığında, arama filtreleme ve arayan kimliği işlevi sağlamak için kullanıcıdan READ_CALL_LOG izni alma zorunluluğu ortadan kalkar.

Aramaları filtrelemek için bir CallScreeningService uygulaması kullanıyorsunuz. Numara kullanıcının kişi listesinde yoksa yeni gelen veya giden aramalar için onScreenCall() işlevini çağırın. Çağrı hakkında bilgi için Call.Details nesnesini kontrol edebilirsiniz. Daha açık belirtecek olursak getCallerNumberVerificationStatus() işlevi, ağ sağlayıcısının diğer numarayla ilgili bilgilerini içerir. Doğrulama durumu başarısız olduysa bu durum aramanın geçersiz bir numaradan veya spam olabilecek bir aramadan geldiğinin iyi bir göstergesidir.

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

Sisteme yeni çağrıya nasıl yanıt vereceğini bildirmek için onScreenCall() işlevini respondToCall() çağıracak şekilde ayarlayın. Bu işlev, sisteme çağrıyı engellemesini, kullanıcı yapmış gibi reddetmesini veya sessize almasını söylemek için kullanabileceğiniz bir CallResponse parametresi alır. Ayrıca sisteme, bu çağrıyı cihazın çağrı kaydına hiç eklememesini de söyleyebilirsiniz.

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());

Sistemin doğru şekilde tetikleyebilmesi için CallScreeningService uygulamasını, uygun intent filtresiyle ve izinle manifest dosyasına kaydetmeniz gerekir.

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