I have used this plugin "Phonegap-SMS-reception-plugin" but I am not able to install it from command prompt or manually. Other than this I cannot find any other plugin for detecting OTP and fetch the data from sms from hybrid mobile app
There is some file missing in that plugin. Use this cordova-plugin-sms
<script type="text/javascript">
var body = "";
var address = "";
$( document ).ready(function() {
if(( /(ipad|iphone|ipod|android)/i.test(navigator.userAgent) )) {
document.addEventListener('deviceready', initApp, false);
} else {
alert('need run on mobile device for full functionalities.');
}
});
function startWatch() { // start listening incoming sms
if(SMS) SMS.startWatch(function(){
alert('watching', 'watching started');
}, function(){
alert('failed to start watching');
});
}
function stopWatch() { // stop listening incoming sms
if(SMS) SMS.stopWatch(function(){
update('watching', 'watching stopped');
}, function(){
updateStatus('failed to stop watching');
});
}
function initApp() {
if (! SMS ) { alert( 'SMS plugin not ready' ); return; }
document.addEventListener('onSMSArrive', function(e){
var sms = e.data;
body = sms.body;
address = sms.address;
});
}
</script>
Be sure that the app has read sms permission granted in Marshmallow.