Sms for react-native android
A react native android module to list/send sms.
Setup
There are five steps in the setup process.
- Install the module via npm.
- Update
android/settings.gradle
file. - Update
android/app/build.gradle
file. - Register the module in
MainActivity.java
file. - Rebuild and restart package manager
- Install the module via npm
npm i --save react-native-android-sms
- Update
android/settings.gradle
file
...include ':react-native-android-sms'project(':react-native-android-sms').projectDir = new File(settingsDir, '../node_modules/react-native-android-sms')
- Update
android/app/build.gradle
file
...dependencies { ... compile project(':react-native-android-sms')}
- Register the module (in
MainActivity.java
file)
// <--First, we import import
- Run
react-native run-android
from your project root directory
Usage
- List all SMS messages matching filters.
var SmsAndroid = ; /* List SMS messages matching the filter */var filter = box: 'inbox' // 'inbox' (default), 'sent', 'draft', 'outbox', 'failed', 'queued', and '' for all // the next 4 filters should NOT be used together, they are OR-ed so pick one read: 0 // 0 for unread SMS, 1 for SMS already read _id: 1234 // specify the msg id address: '+97433------' // sender's phone number body: 'Hello' // content to match // the next 2 filters can be used for pagination indexFrom: 0 // start from index 0 maxCount: 10 // count of SMS to return each time; SmsAndroid; /* Each sms will be represents by a JSON object represented below { "_id": 1234, "thread_id": 3, "address": "2900", "person": -1, "date": 1365053816196, "date_sent": 0, "protocol": 0, "read": 1, "status": -1, "type": 1, "body": "Hello There, I am an SMS", "service_center": "+60162999922", "locked": 0, "error_code": -1, "sub_id": -1, "seen": 1, "deletable": 0, "sim_slot": 0, "hidden": 0, "app_id": 0, "msg_id": 0, "reserved": 0, "pri": 0, "teleservice_id": 0, "svc_cmd": 0, "roam_pending": 0, "spam_report": 0, "secret_mode": 0, "safe_message": 0, "favorite": 0} */
- Send an SMS
var SmsAndroid = ;var text = "Hello ... QASH I AM YOUR FATHER !!!!!";var addressList = addressList: "+97433------" "+97434------" SmsAndroid;
- Delete an SMS (coming soon)