Verifica automatica tramite SMS con l'API SMS Retriever
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Con l'API SMS Fetcher, puoi eseguire la verifica utente basata su SMS nella tua app Android automaticamente, senza che l'utente debba digitare manualmente i codici di verifica e senza richiedere autorizzazioni app aggiuntive. Quando implementi la verifica automatica via SMS nell'app, il flusso di verifica ha il seguente aspetto:

- Un utente avvia la verifica tramite SMS nell'app. L'app potrebbe richiedere all'utente
di fornire un numero di telefono o utilizzare il
selettore di suggerimenti Smart Lock per password
se l'informazione non era necessaria per creare l'account.
- La tua app invia una richiesta al tuo server per verificare il numero di telefono dell'utente.
A seconda delle informazioni disponibili nel tuo database utente, questa richiesta potrebbe includere l'ID utente, il numero di telefono dell'utente o entrambi.
- Allo stesso tempo, la tua app chiama l'API SMS Fetcher per iniziare ad ascoltare una risposta SMS dal tuo server.
- Il server invia all'utente un messaggio SMS che include un codice monouso da inviare nuovamente al server e un hash che identifica la tua app.
- Quando il dispositivo dell'utente riceve il messaggio SMS, Google Play Services utilizza l'hash dell'app per determinare se il messaggio è destinato alla tua app e mette a disposizione il testo del messaggio all'app tramite l'API SMS Fetchr.
- L'app analizza il codice monouso dal testo del messaggio e lo invia al tuo server.
- Il server riceve il codice monouso dalla tua app, lo verifica e infine registra che l'utente ha verificato il proprio account.
Per implementare la verifica automatica degli SMS nell'app, consulta le guide per Android e per i server:
Guida di Android
Guida del server
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-07-25 UTC.
[null,null,["Ultimo aggiornamento 2025-07-25 UTC."],[[["\u003cp\u003eThe SMS Retriever API enables automatic SMS verification in Android apps, eliminating manual code entry for users.\u003c/p\u003e\n"],["\u003cp\u003eThis API streamlines user verification by having your app listen for an SMS message containing a one-time code, sent by your server after a verification request.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Play services identifies the incoming SMS message as intended for your app using an app hash included in the message, ensuring secure delivery of the verification code.\u003c/p\u003e\n"],["\u003cp\u003eThe SMS Retriever API enhances user experience and security by automating verification without requiring extra app permissions.\u003c/p\u003e\n"]]],[],null,["# Automatic SMS Verification with the SMS Retriever API\n\nWith the SMS Retriever API, you can perform SMS-based user verification in your\nAndroid app automatically, without requiring the user to manually type\nverification codes, and without requiring any extra app permissions. When you\nimplement automatic SMS verification in your app, the verification flow looks\nlike this:\n\n[](/static/identity/sms-retriever/flow-overview.png)\n\n1. A user initiates SMS verification in your app. Your app might prompt the user to provide a phone number or use the [Smart Lock for Passwords hint selector](/identity/smartlock-passwords/android/retrieve-hints) if that information wasn't required to create the user's account.\n2. Your app makes a request to your server to verify the user's phone number. Depending on what information is available in your user database, this request might include the user's ID, the user's phone number, or both.\n3. At the same time, your app calls the SMS Retriever API to begin listening for an SMS response from your server.\n4. Your server sends an SMS message to the user that includes a one-time code to be sent back to your server, and a hash that identifies your app.\n5. When the user's device receives the SMS message, Google Play services uses the app hash to determine that the message is intended for your app, and makes the message text available to your app through the SMS Retriever API.\n6. Your app parses out the one-time code from the message text and sends it back to your server.\n7. Your server receives the one-time code from your app, verifies the code, and finally records that the user has successfully verified their account.\n\nTo implement automatic SMS verification in your app, see the Android and server\nguides:\n\n[Android Guide](/identity/sms-retriever/request)\n[Server Guide](/identity/sms-retriever/verify)"]]