There are many ways to do the verification process in an Android application. One of the best way is using SMS verification. Since we all know most mobile phone users have a phone number for their phone.
有许多方法可以在Android应用程序中执行验证过程。 最好的方法之一是使用SMS验证。 众所周知,大多数手机用户都有其手机的电话号码。
But, input the code that we received from SMS isn’t user friendly. You have to view all the messages in your phone and see the code on it, then back again to the app to input the code. We need “something” that can read those messages and get the code then fill in the field automatically.
但是,输入我们从SMS收到的代码不是用户友好的。 您必须查看手机中的所有消息并查看其中的代码,然后再次返回到应用程序以输入代码。 我们需要可以读取这些消息并获取代码的“东西”,然后自动填写该字段。
Actually, there are many ways to automatically fill the OTP field by reading the message in our phone using READ_SMS permission. But, Google has strictly prohibited the usage of that permission for security purposes. You can read the full explanation here.
实际上,有很多方法可以通过使用READ_SMS权限在手机中读取消息来自动填写OTP字段。 但是,Google出于安全目的严格禁止使用该权限。 您可以在此处阅读完整的说明 。
Since we can’t use the READ_SMS permission anymore, Google has given some other choices to implement automatic SMS verification using SMS Verification API which includes the automatic and one-tap SMS verification. Let’s find out how they work!
由于我们无法再使用READ_SMS权限,因此Google提供了其他一些选择,以使用SMS验证API实现自动SMS验证,该API包括自动和一键式SMS验证。 让我们找出它们是如何工作的!
自动短信验证 (Automatic SMS Verification)
The automatic SMS verification is the best way to do the SMS verification. Because, users don’t have to do any action and just wait until the verification process is complete. Also, it doesn’t require any permission, but you have to make sure that you follow these criterias:
自动SMS验证是进行SMS验证的最佳方法。 因为,用户无需执行任何操作,只需等待验证过程完成即可。 另外,它不需要任何许可,但是您必须确保遵循以下条件:
- Messages that are sent to the user’s device must be no longer than 140 bytes. 发送到用户设备的消息不得超过140个字节。
- Message must contains a one-time code that user’s will send back to the server. 消息必须包含一个一次性代码,用户的一次性代码将发送回服务器。
Message must contain an 11-character hash string.
邮件必须包含11个字符的哈希字符串 。
Now, let’s impleme