Filtro delle chiamate
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
I dispositivi con Android 10 (livello API 29) o versioni successive consentono alla tua app di identificare
Chiamate da numeri non presenti nella rubrica dell'utente come potenziale spam
chiamate. Gli utenti possono scegliere di rifiutare automaticamente le chiamate indesiderate. Per offrire una maggiore
trasparenza per gli utenti quando perdono le chiamate, le informazioni
vengono registrate nel registro chiamate. L'utilizzo dell'API Android 10 elimina
requisito di ottenere
READ_CALL_LOG
autorizzazione da parte dell'utente per fornire il filtro delle chiamate e l'ID chiamante
funzionalità.
Utilizzi un
CallScreeningService
per filtrare le chiamate. Chiama il
onScreenCall()
per qualsiasi nuova chiamata in arrivo o in uscita quando il numero non è nella
elenco contatti dell'utente. Puoi controllare
Call.Details
oggetto per le informazioni
in merito alla chiamata. In particolare,
getCallerNumberVerificationStatus()
include informazioni del provider di rete sull'altro numero.
Se lo stato della verifica non è andato a buon fine, significa che la chiamata è
da un numero non valido o una potenziale chiamata indesiderata.
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
}
}
}
}
Imposta la funzione onScreenCall()
da chiamare
respondToCall()
per indicare al sistema come rispondere alla nuova chiamata. Questa funzione prende un
CallResponse
parametro che puoi utilizzare per indicare al sistema di bloccare la chiamata, rifiutarla come se
l'utente lo ha fatto o silenziarlo. Puoi anche indicare al sistema di saltare l'aggiunta
tutte le chiamate al registro chiamate del dispositivo.
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());
Devi registrare l'implementazione di CallScreeningService
nel file manifest
con il filtro per intent e l'autorizzazione appropriati in modo che il sistema possa attivare
in modo corretto.
<service
android:name=".ScreeningService"
android:permission="android.permission.BIND_SCREENING_SERVICE">
<intent-filter>
<action android:name="android.telecom.CallScreeningService" />
</intent-filter>
</service>
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-08-28 UTC.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-08-28 UTC."],[],[],null,["Devices that run Android 10 (API level 29) or higher allow your app to identify\ncalls from numbers that aren't in the user's address book as potential spam\ncalls. Users can choose to have spam calls silently rejected. To provide greater\ntransparency to users when they miss calls, information about these blocked\ncalls is logged in the call log. Using the Android 10 API eliminates the\nrequirement to obtain the\n[`READ_CALL_LOG`](/reference/android/Manifest.permission#READ_CALL_LOG)\npermission from the user in order to provide call screening and caller ID\nfunctionality.\n\nYou use a\n[`CallScreeningService`](/reference/android/telecom/CallScreeningService)\nimplementation to screen calls. Call the\n[`onScreenCall()`](/reference/android/telecom/CallScreeningService#onScreenCall(android.telecom.Call.Details))\nfunction for any new incoming or outgoing calls when the number is not in the\nuser's contact list. You can check the\n[`Call.Details`](/reference/android/telecom/Call.Details) object for information\nabout the call. Specifically, the\n[`getCallerNumberVerificationStatus()`](/reference/android/telecom/Call.Details#getCallerNumberVerificationStatus())\nfunction includes information from the network provider about the other number.\nIf the verification status failed, this is a good indication that the call is\nfrom an invalid number or a potential spam call. \n\nKotlin \n\n```kotlin\nclass ScreeningService : CallScreeningService() {\n // This function is called when an ingoing or outgoing call\n // is from a number not in the user's contacts list\n override fun onScreenCall(callDetails: Call.Details) {\n // Can check the direction of the call\n val isIncoming = callDetails.callDirection == Call.Details.DIRECTION_INCOMING\n\n if (isIncoming) {\n // the handle (e.g. phone number) that the Call is currently connected to\n val handle: Uri = callDetails.handle\n\n // determine if you want to allow or reject the call\n when (callDetails.callerNumberVerificationStatus) {\n Connection.VERIFICATION_STATUS_FAILED -\u003e {\n // Network verification failed, likely an invalid/spam call.\n }\n Connection.VERIFICATION_STATUS_PASSED -\u003e {\n // Network verification passed, likely a valid call.\n }\n else -\u003e {\n // Network could not perform verification.\n // This branch matches Connection.VERIFICATION_STATUS_NOT_VERIFIED.\n }\n }\n }\n }\n}\n```\n\nJava \n\n```java\nclass ScreeningService extends CallScreeningService {\n @Override\n public void onScreenCall(@NonNull Call.Details callDetails) {\n boolean isIncoming = callDetails.getCallDirection() == Call.Details.DIRECTION_INCOMING;\n\n if (isIncoming) {\n Uri handle = callDetails.getHandle();\n\n switch (callDetails.getCallerNumberVerificationStatus()) {\n case Connection.VERIFICATION_STATUS_FAILED:\n // Network verification failed, likely an invalid/spam call.\n break;\n case Connection.VERIFICATION_STATUS_PASSED:\n // Network verification passed, likely a valid call.\n break;\n default:\n // Network could not perform verification.\n // This branch matches Connection.VERIFICATION_STATUS_NOT_VERIFIED\n }\n }\n }\n}\n```\n\nSet the `onScreenCall()` function to call\n[`respondToCall()`](/reference/android/telecom/CallScreeningService#respondToCall(android.telecom.Call.Details,%20android.telecom.CallScreeningService.CallResponse))\nto tell the system how to respond to the new call. This function takes a\n[`CallResponse`](/reference/android/telecom/CallScreeningService.CallResponse)\nparameter that you can use to tell the system to block the call, reject it as if\nthe user did, or silence it. You can also tell the system to skip adding this\ncall to the device's call log altogether. \n\nKotlin \n\n```kotlin\n// Tell the system how to respond to the incoming call\n// and if it should notify the user of the call.\nval response = CallResponse.Builder()\n // Sets whether the incoming call should be blocked.\n .setDisallowCall(false)\n // Sets whether the incoming call should be rejected as if the user did so manually.\n .setRejectCall(false)\n // Sets whether ringing should be silenced for the incoming call.\n .setSilenceCall(false)\n // Sets whether the incoming call should not be displayed in the call log.\n .setSkipCallLog(false)\n // Sets whether a missed call notification should not be shown for the incoming call.\n .setSkipNotification(false)\n .build()\n\n// Call this function to provide your screening response.\nrespondToCall(callDetails, response)\n```\n\nJava \n\n```java\n// Tell the system how to respond to the incoming call\n// and if it should notify the user of the call.\nCallResponse.Builder response = new CallResponse.Builder();\n// Sets whether the incoming call should be blocked.\nresponse.setDisallowCall(false);\n// Sets whether the incoming call should be rejected as if the user did so manually.\nresponse.setRejectCall(false);\n// Sets whether ringing should be silenced for the incoming call.\nresponse.setSilenceCall(false);\n// Sets whether the incoming call should not be displayed in the call log.\nresponse.setSkipCallLog(false);\n// Sets whether a missed call notification should not be shown for the incoming call.\nresponse.setSkipNotification(false);\n\n// Call this function to provide your screening response.\nrespondToCall(callDetails, response.build());\n```\n\nYou must register the `CallScreeningService` implementation in the manifest\nfile with the appropriate intent filter and permission so the system can trigger\nit correctly. \n\n \u003cservice\n android:name=\".ScreeningService\"\n android:permission=\"android.permission.BIND_SCREENING_SERVICE\"\u003e\n \u003cintent-filter\u003e\n \u003caction android:name=\"android.telecom.CallScreeningService\" /\u003e\n \u003c/intent-filter\u003e\n \u003c/service\u003e"]]