sms-getter
v0.0.2
Published
Read sms messages for capacitor (Android only)
Downloads
5
Readme
sms-getter
Read sms messages for capacitor (Android only)
Install
npm install sms-getter
npx cap sync
Usage
import { SmsGetter } from 'sms-getter';
async startWatchingSms() {
let permission = false;
try {
await SmsGetter.startWatch();
permission = true;
console.log('Started watching for incoming SMS');
} catch (error) {
permission = false;
console.error('Error starting SMS watch:', error);
}
if (permission) {
// Listen for SMS events
SmsGetter.addListener('smsReceived', (sms) => {
console.log(sms);
});
}
}
API
startWatch()
startWatch() => Promise<void>
Starts the SMS receiver to watch for incoming SMS.
addListener('smsReceived', ...)
addListener(eventName: 'smsReceived', listenerFunc: (data: { sender: string; message: string; }) => void) => Promise<PluginListenerHandle>
Adds an event listener for the 'smsReceived' event.
| Param | Type | Description |
| ------------------ | -------------------------------------------------------------------- | ---------------------------------------------- |
| eventName
| 'smsReceived' | The event name, which is 'smsReceived'. |
| listenerFunc
| (data: { sender: string; message: string; }) => void | The function to call when the SMS is received. |
Returns: Promise<PluginListenerHandle>
Interfaces
PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove
| () => Promise<void> |