5.0.3 • Published 9 months ago

@solimanware/capacitor-sms-reader v5.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

capacitor-sms-inbox

A Capacitor plugin to read SMS inbox on Android devices.

Installation

  1. Install the plugin:
npm i git+https://github.com/solimanware/capacitor-sms-reader.git
  1. Sync your Capacitor project:
npx cap sync android
  1. Add the following permissions to your AndroidManifest.xml file:
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
  1. In your Capacitor config file (usually capacitor.config.json or capacitor.config.ts), add the following:
{
  "plugins": {
    "SMSInboxReader": {
      "android": {
        "name": "com.capacitor.sms.reader.SMSInboxReaderPlugin"
      }
    }
  }
}
  1. Import and initialize the plugin in your TypeScript/JavaScript code:
import { Plugins } from '@capacitor/core';
import { SMSInboxReader } from 'capacitor-sms-reader';

// Use the plugin
const { SMSInboxReader } = Plugins;

// Check permissions
const permissionStatus = await SMSInboxReader.checkPermissions();
if (permissionStatus.sms !== 'granted') {
  await SMSInboxReader.requestPermissions();
}

// Now you can use other methods like getCount(), getSMSList(), etc.

Usage

After installation, you can use the plugin's methods to interact with the SMS inbox. Remember to always check and request permissions before accessing SMS data.

For detailed API documentation, see the API section below.

API

Plugin interface for reading messages from the device's inbox.

getMessages(...)

getMessages(filter: GetMessageFilterInput) => Promise<{ messages: MessageObject[]; }>

Retrieves messages based on the provided filter criteria.

ParamTypeDescription
filterGetMessageFilterInput- The filter criteria to apply when fetching messages.

Returns: Promise<{ messages: MessageObject[]; }>


checkPermissions()

checkPermissions() => Promise<PermissionStatus>

Checks the current permission status for accessing messages.

Returns: Promise<PermissionStatus>


requestPermissions()

requestPermissions() => Promise<PermissionStatus>

Requests permissions to access messages on the device.

Returns: Promise<PermissionStatus>


Interfaces

MessageObject

Represents a message object with its properties.

PropTypeDescription
idstringUnique identifier of the message.
datenumberTimestamp of the message in milliseconds since epoch.
messageType'sms' | 'mms'Type of the message, either 'sms' or 'mms'.
senderstringPhone number or address of the sender/recipient.
bodystringContent of the message.

GetMessageFilterInput

Input parameters for filtering messages.

PropTypeDescription
idsstring[]Array of message IDs to filter by.
bodystringText to search for in the message body.
senderstringPhone number or address to filter by.
minDatenumberMinimum date (in milliseconds since epoch) to filter messages.
maxDatenumberMaximum date (in milliseconds since epoch) to filter messages.
indexFromnumberStarting index for pagination.
indexTonumberEnding index for pagination.
limitnumberMaximum number of messages to return.

PermissionStatus

Represents the permission status for accessing messages.

PropTypeDescription
messagesPermissionStateThe current permission state for accessing messages.

Type Aliases

PermissionState

'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'

5.0.3

9 months ago

5.0.2

9 months ago

5.0.1

9 months ago

5.0.0

9 months ago

4.0.0

9 months ago

3.5.0

9 months ago

3.0.0

9 months ago

2.0.3

9 months ago

2.0.2

9 months ago

2.0.1

9 months ago

1.0.10

9 months ago

1.0.9

9 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago