After the google's new policy regarding SMS and Call log permissions, I am trying to implement SMS retriever API for my android application. The tutorial seems easy but I found a problem while creating/generating hash for the same.
When I type
keytool -alias MyAndroidKey -exportcert -keystore MyProduction.keystore | xxd -p | tr -d "[:space:]"
OR
keytool -exportcert -alias MyAndroidKey -keystore MyProductionKeys.keystore | xxd -p | tr -d "[:space:]" | echo -n com.example.myapp `cat` | sha256sum | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11
It says:
'xxd' is not recognized as an internal or external command,
operable program or batch file.
'tr' is not recognized as an internal or external command,
operable program or batch file.
There are no clarification available on https://developers.google.com/identity/sms-retriever/verify#computing_your_apps_hash_string page
Thanks.
Alternatively, you can get your app's hash string with the AppSignatureHelper class from the SMS retriever sample app. However, if you use the helper class, be sure to remove it from your app after you get the hash string. Do not use hash strings dynamically computed on the client in your verification messages.
The SMS Retriever API is available only on Android devices with Play services version 10.2 and newer. When a client’s phone receives any message containing a unique string, SMS Retriever API will broadcast the message with SmsRetriever.SMS_RETRIEVED_ACTION intent. Then, we should use a broadcast receiver to receive the verification message.
11 digit unique hash string is the key used for auto verifying SMS. Google Play Services utilizes the hash string to figure out which check messages to send to your application. This unique hash can be different for different environments.
Google Play services uses the hash string to determine which verification messages to send to your app. The hash string is made of your app’s package name and your app’s public key certificate. To generate the hash string: Let’s create a class named is AppSignatureHelper and paste the below code. This is the simplest way to get hash string.
Finally I managed to get hash key for using SMS retriever API - Android.
Steps I followed.
I was using Git so it was installed on my machine. Head over to C:\Program Files\Git\usr\bin and I see that it has xxd.exe and tr.exe which was my requirement.
So I added the environment variable to Path > New > C:\Program Files\Git\usr\bin
Restart the cmd with administrator privileges. xxd and tr command started working.
Hope this will help others as google has stopped CALL_LOG, READ_SMS permission.
Cheers.
---------------------UPDATE-----------------------
I found an another good answer here.
Please follow the link it gives a step by step tut for creating the hash key.
I followed this because after publishing app to play store the generated hash key doesn't work any more.
How to generate 11 char hash key for Sms Retriever with Google App signing
Hope it will help someone!
[UPDATED for windows]
# xxd
C:\Program Files\Git\usr\bin\xxd
# tr
C:\Program Files\Git\usr\bin\tr
# base64
C:\Program Files\Git\usr\bin\base64
The whole commands become
keytool -exportcert -alias YOUR_ALIAS -keystore certificate.jks | "C:\Program Files\Git\usr\bin\xxd" -p |"C:\Program Files\Git\usr\bin\tr" -d "[:space:]" | echo -n PACKAGE_NAME `cat` | "C:\Program Files\Git\usr\bin\sha256sum" | "C:\Program Files\Git\usr\bin\tr" -d "[:space:]-" | "C:\Program Files\Git\usr\bin\xxd" -r -p | "C:\Program Files\Git\usr\bin\base64" | "C:\Program Files\Git\usr\bin\cut" -c1-11
In Window, if you are using SourceTree you will search with xxd.exe
keyword or find it with C:\Users\your_user_name\AppData\Local\Atlassian\SourceTree\git_local\usr\bin
path.
Example: keytool -alias MyKey -exportcert -keystore MyKey.keystore | C:\Users\your_user_name\AppData\Local\Atlassian\SourceTree\git_local\usr\bin\xxd -p | C:\Users\your_user_name\AppData\Local\Atlassian\SourceTree\git_local\usr\bin\tr -d "[:space:]"
You can download here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With