Easily retrieve SMS messages using the Google SMS Retriever API with our cross-platform plugin designed for Ionic/Cordova. This powerful tool streamlines the process and is specifically available for Android devices.
npm install cordova-plugin-sms-retriever-manager
ionic cordova plugin add cordova-plugin-sms-retriever-manager
npm install @ionic-native/sms-retriever
`
It is also possible to install via repo url directly (unstable), run :
`sh
ionic cordova plugin add https://github.com/hanatharesh2712/ionic-native-sms-retriever-plugin-master.git
`
You can find working Demo for Cordova here: https://github.com/hanatharesh2712/automatic-sms-cordova/tree/main/hello
Using the plugin
HTML
`html
`
Javascript
`js
document.querySelector('.hashCode').addEventListener('click', this.getAppHash);
document.querySelector('.startWatching').addEventListener('click', this.retriveSMS);
var app = {
getAppHash: function() {
window['cordova']['plugins']['smsRetriever']'getAppHash' => {
// Once you get this hash code of your app. Please remove this code.
alert(result);
console.log('Hash', result);
},
(err) => {
console.log(err);
});
},
retriveSMS: function() {
window['cordova']['plugins']['smsRetriever']'startWatching' => {
alert(result.Message);
console.log('Message', result);
},
// the second is the error callback where we get back the errors
(err) => {
console.log(err);
});
}
};
`
You can find working Demo for Ionic 4 here: https://github.com/hanatharesh2712/sms-plugin-test
Typescript (Ionic 4)
`typescript
import { SmsRetriever } from '@ionic-native/sms-retriever/ngx';
constructor(private smsRetriever: SmsRetriever) { }
...
// This function is to get hash string of APP.
// * @return {Promise} Returns a promise that resolves when successfully generate hash of APP.
this.smsRetriever.getAppHash()
.then((res: any) => console.log(res))
.catch((error: any) => console.error(error));
// * This function start wathching message arrive event and retrive message text.
// * @return {Promise} Returns a promise that resolves when retrives SMS text or TIMEOUT after 5 min.
this.smsRetriever.startWatching()
.then((res: any) => console.log(res))
.catch((error: any) => console.error(error));
`
You can find working Demo for Ionic 3 here: https://github.com/hanatharesh2712/sms-plugin-test-ionic-3
Typescript (Ionic 3)
`typescript
import { SmsRetriever } from '@ionic-native/sms-retriever/ngx';
var smsRetriever = window['cordova']['plugins']['smsRetriever'];
public smsTextmessage: string = '';
public appHashString: string = '';
constructor(private smsRetriever: SmsRetriever) { }
...
getHashCode() {
smsRetriever'getAppHash' => {
this.appHashString = res;
console.log(res);
}, (err) => {
console.warn(err);
}
);
}
getSMS() {
smsRetriever'startWatching' => {
this.smsTextmessage = res.Message;
console.log(res);
}, (err) => {
console.warn(err);
}
);
}
``