Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
cordova-plugin-sms-retriever
Advanced tools
Cordova plugin to retrieve SMS in Android using the SMS Retriever API.
Cordova plugin to receive verification SMS in Android using the SMS Retriever API.
This plugin requires the Google Play Services 15.0.0 or newer in order to work properly.
Minimum supported SDK version 21.
<platform name="android">
...
<preference name="android-minSdkVersion" value="21" />
...
</platform>
cordova plugin add cordova-plugin-sms-retriever
cordova plugin add https://github.com/andreszs/cordova-plugin-sms-retriever
npm i awesome-cordova-plugins-sms-retriever-api
npm i @awesome-cordova-plugins/sms-retriever-api
https://github.com/MaximBelov/cordova-plugin-sms-retriever-lab
Opens a dialog to select your mobile numbers saved in phone and returns selected phone number.
var onSuccess = function (strSuccess) {
console.log(strSuccess);
};
var onFail = function (strError) {
console.log(strError);
};
cordova.plugins.SMSRetriever.getPhoneNumber(onSuccess, onFail);
Start listening for a single incoming verification SMS for 5 minutes.
cordova.plugins.SMSRetriever.startWatch(successCallback, errorCallback);
:warning: Method moved from window to cordova.plugins object in version 2.0.0
When the SMS is returned, the retriever API is automatically stopped and no further messages will be intercepted until you start a new one. This is by API design, not a plugin or a demo app restriction.
var onSuccess = function (strSuccess) {
console.log(strSuccess);
};
var onFail = function (strError) {
console.log(strError);
};
cordova.plugins.SMSRetriever.startWatch(onSuccess, onFail);
Stops listening for a single incoming verification SMS
var onSuccess = function (strSuccess) {
console.log(strSuccess);
};
var onFail = function (strError) {
console.log(strError);
};
cordova.plugins.SMSRetriever.stopWatch(onSuccess, onFail);
Get the 11-character hash string for your app using the AppSignatureHelper class. This string must be appended to the SMS received in order for the API to read this message.
cordova.plugins.SMSRetriever.getHashString(successCallback, errorCallback);
:warning: Method moved from window to cordova.plugins object in version 2.0.0
Do not use hash strings dynamically computed on the client in your verification messages.
Therefore, do not invoke this method from the published app. The hash is the same for all users, and bound to your keystore signing keys, so you can get it once and never again call this method.
var onSuccess = function (strHash) {
console.log(strHash);
};
var onFail = function (strError) {
console.log(strError);
};
cordova.plugins.SMSRetriever.getHashString(onSuccess , onFail);
Event fired when a valid verification SMS with the hash string has arrived. You need call startWatch() first.
document.addEventListener('onSMSArrive', function(args) {
// SMS retrieved, get its contents
console.info(args.message);
// To Do: Extract the received one-time code and verify it on your server
});
The verification SMS message you send to the user must:
Otherwise, the contents of the verification message can be whatever you choose. It is helpful to create a message from which you can easily extract the one-time code later on. For example, a valid verification message might look like the following:
<#> AZC123 is your code for andreszsogon.com SMS Retriever Demo App. hi5c8+bkQy0
:information_source: It is a good practice to prepend the verification code to the beginning of the SMS, in case the retriever fails, the user can see the code immediately from the notification bar.
The plugin will work in your emulator as long as you are using a Google Play ABI or System Image, instead of the regular Google APIs ones. This is because these images include the Google Play Store and Google Play Services.
When the app is sent to the background, as long as Android has not unloaded it to recover memory, SMS watching will remain active and working correctly for 5 minutes.
No, the plugin does not require any permission because it relies on the SMS Retriever API.
In the emulator you can test the plugin using the unsigned debug APK. Real devices require the production APK to work.
Google advices against computing the hash string in the client for security concerns. Get the hash string in advance and then do not call the get hash method again in the final production app.
The <#> prefix formerly required to retrieve the SMS was silently removed in an unknown Play Services version and no longer appears in the SMS Retriever API docs.
FAQs
Cordova plugin to retrieve SMS in Android using the SMS Retriever API.
The npm package cordova-plugin-sms-retriever receives a total of 129 weekly downloads. As such, cordova-plugin-sms-retriever popularity was classified as not popular.
We found that cordova-plugin-sms-retriever demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.