├── .flowconfig ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── index.android.js ├── package.json ├── proguard-rules.pro └── src └── main ├── AndroidManifest.xml ├── java └── my │ └── qash │ └── react │ ├── SmsModule.java │ ├── SmsPackage.java │ └── tmpwryl6c └── res ├── mipmap-hdpi └── ic_launcher.png ├── mipmap-mdpi └── ic_launcher.png ├── mipmap-xhdpi └── ic_launcher.png ├── mipmap-xxhdpi └── ic_launcher.png └── values ├── strings.xml └── styles.xml /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | 3 | # We fork some components by platform. 4 | .*/*.web.js 5 | .*/*.android.js 6 | 7 | # Some modules have their own node_modules with overlap 8 | .*/node_modules/node-haste/.* 9 | 10 | # Ignore react-tools where there are overlaps, but don't ignore anything that 11 | # react-native relies on 12 | .*/node_modules/react-tools/src/React.js 13 | .*/node_modules/react-tools/src/renderers/shared/event/EventPropagators.js 14 | .*/node_modules/react-tools/src/renderers/shared/event/eventPlugins/ResponderEventPlugin.js 15 | .*/node_modules/react-tools/src/shared/vendor/core/ExecutionEnvironment.js 16 | 17 | # Ignore commoner tests 18 | .*/node_modules/commoner/test/.* 19 | 20 | # See https://github.com/facebook/flow/issues/442 21 | .*/react-tools/node_modules/commoner/lib/reader.js 22 | 23 | # Ignore jest 24 | .*/node_modules/jest-cli/.* 25 | 26 | # Ignore Website 27 | .*/website/.* 28 | 29 | [include] 30 | 31 | [libs] 32 | Libraries/react-native/react-native-interface.js 33 | 34 | [options] 35 | module.system=haste 36 | 37 | munge_underscores=true 38 | 39 | module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub' 40 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.png$' -> 'RelativeImageStub' 41 | 42 | suppress_type=$FlowIssue 43 | suppress_type=$FlowFixMe 44 | suppress_type=$FixMe 45 | 46 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(1[0-7]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 47 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(1[0-7]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)? #[0-9]+ 48 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 49 | 50 | [version] 51 | 0.17.0 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/workspace.xml 2 | .idea/libraries 3 | .gradle 4 | local.properties 5 | *.iml 6 | build 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Nishanth Shankar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sms for react-native android 2 | 3 | A react native android module to list/send sms. 4 | 5 | [![npm](https://img.shields.io/npm/v/react-native-android-sms.svg?style=flat-square)](https://www.npmjs.com/package/react-native-android-sms) 6 | 7 | [![GitHub tag](https://img.shields.io/github/tag/msmakhlouf/react-native-android-sms.svg?style=flat-square)](https://github.com/msmakhlouf/react-native-android-sms) 8 | 9 | ## Setup 10 | 11 | There are five steps in the setup process. 12 | 13 | 1. Install the module via npm. 14 | 2. Update `android/settings.gradle` file. 15 | 3. Update `android/app/build.gradle` file. 16 | 4. Register the module in `MainActivity.java` file. 17 | 5. Rebuild and restart package manager 18 | 19 | * Install the module via npm 20 | ```bash 21 | npm i --save react-native-android-sms 22 | ``` 23 | 24 | * Update `android/settings.gradle` file 25 | 26 | ```gradle 27 | ... 28 | include ':react-native-android-sms' 29 | project(':react-native-android-sms').projectDir = new File(settingsDir, '../node_modules/react-native-android-sms') 30 | ``` 31 | 32 | * Update `android/app/build.gradle` file 33 | 34 | ```gradle 35 | ... 36 | dependencies { 37 | ... 38 | compile project(':react-native-android-sms') 39 | } 40 | ``` 41 | 42 | * Register the module (in `MainActivity.java` file) 43 | 44 | ```java 45 | import my.qash.react.SmsPackage; // <--First, we import import 46 | 47 | public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler { 48 | 49 | ...... 50 | private static Activity mActivity = null; 51 | 52 | @Override 53 | protected void onCreate(Bundle savedInstanceState) { 54 | super.onCreate(savedInstanceState); 55 | mReactRootView = new ReactRootView(this); 56 | 57 | mActivity = this; 58 | mReactInstanceManager = ReactInstanceManager.builder() 59 | .setApplication(getApplication()) 60 | .setBundleAssetName("index.android.bundle") 61 | .setJSMainModuleName("index.android") 62 | .addPackage(new MainReactPackage()) 63 | .addPackage(new SmsPackage(this)) // <------- Then, we add the package 64 | .setUseDeveloperSupport(BuildConfig.DEBUG) 65 | .setInitialLifecycleState(LifecycleState.RESUMED) 66 | .build(); 67 | 68 | mReactRootView.startReactApplication(mReactInstanceManager, "MyExampleApp", null); 69 | 70 | setContentView(mReactRootView); 71 | } 72 | 73 | ...... 74 | 75 | } 76 | ``` 77 | * Run `react-native run-android` from your project root directory 78 | 79 | 80 | 81 | 82 | ## Usage 83 | 84 | - List all SMS messages matching filters. 85 | 86 | ```js 87 | var SmsAndroid = require('react-native-android-sms'); 88 | 89 | /* List SMS messages matching the filter */ 90 | var filter = { 91 | box: 'inbox', // 'inbox' (default), 'sent', 'draft', 'outbox', 'failed', 'queued', and '' for all 92 | // the next 4 filters should NOT be used together, they are OR-ed so pick one 93 | read: 0, // 0 for unread SMS, 1 for SMS already read 94 | _id: 1234, // specify the msg id 95 | address: '+97433------', // sender's phone number 96 | body: 'Hello', // content to match 97 | // the next 2 filters can be used for pagination 98 | indexFrom: 0, // start from index 0 99 | maxCount: 10, // count of SMS to return each time 100 | }; 101 | 102 | SmsAndroid.list(JSON.stringify(filter), (fail) => { 103 | console.log("OH Snap: " + fail) 104 | }, 105 | (count, smsList) => { 106 | console.log('Count: ', count); 107 | console.log('List: ', smsList); 108 | var arr = JSON.parse(smsList); 109 | for (var i = 0; i < arr.length; i++) { 110 | var obj = arr[i]; 111 | console.log("Index: " + i); 112 | console.log("-->" + obj.date); 113 | console.log("-->" + obj.body); 114 | } 115 | }); 116 | 117 | /* 118 | Each sms will be represents by a JSON object represented below 119 | 120 | { 121 | "_id": 1234, 122 | "thread_id": 3, 123 | "address": "2900", 124 | "person": -1, 125 | "date": 1365053816196, 126 | "date_sent": 0, 127 | "protocol": 0, 128 | "read": 1, 129 | "status": -1, 130 | "type": 1, 131 | "body": "Hello There, I am an SMS", 132 | "service_center": "+60162999922", 133 | "locked": 0, 134 | "error_code": -1, 135 | "sub_id": -1, 136 | "seen": 1, 137 | "deletable": 0, 138 | "sim_slot": 0, 139 | "hidden": 0, 140 | "app_id": 0, 141 | "msg_id": 0, 142 | "reserved": 0, 143 | "pri": 0, 144 | "teleservice_id": 0, 145 | "svc_cmd": 0, 146 | "roam_pending": 0, 147 | "spam_report": 0, 148 | "secret_mode": 0, 149 | "safe_message": 0, 150 | "favorite": 0 151 | } 152 | 153 | */ 154 | 155 | 156 | ``` 157 | 158 | - Send an SMS 159 | 160 | ```js 161 | var SmsAndroid = require('react-native-android-sms'); 162 | var text = "Hello ... QASH I AM YOUR FATHER !!!!!"; 163 | var addressList = { 164 | addressList: [ 165 | "+97433------", "+97434------" 166 | ] 167 | } 168 | 169 | SmsAndroid.send(JSON.stringify(addressList), text, (fail) => { 170 | console.log("OH Snap: " + fail) 171 | }, 172 | (status) => { 173 | console.log('Status: ', status); 174 | }); 175 | 176 | ``` 177 | 178 | - Delete an SMS (coming soon) 179 | 180 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | google() 4 | jcenter() 5 | } 6 | 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:3.3.0' 9 | } 10 | } 11 | 12 | apply plugin: 'com.android.library' 13 | 14 | def safeExtGet(prop, fallback) { 15 | rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback 16 | } 17 | 18 | android { 19 | compileSdkVersion safeExtGet('compileSdkVersion', 28) 20 | 21 | defaultConfig { 22 | minSdkVersion safeExtGet('minSdkVersion', 16) 23 | targetSdkVersion safeExtGet('targetSdkVersion', 28) 24 | versionCode 1 25 | versionName "1.0" 26 | } 27 | lintOptions { 28 | abortOnError false 29 | } 30 | } 31 | 32 | repositories { 33 | google() 34 | maven { 35 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 36 | url "$rootDir/../node_modules/react-native/android" 37 | } 38 | jcenter() 39 | } 40 | 41 | dependencies { 42 | compileOnly "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}" 43 | } 44 | -------------------------------------------------------------------------------- /index.android.js: -------------------------------------------------------------------------------- 1 | var { NativeModules } = require('react-native'); 2 | module.exports = NativeModules.Sms; 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-android-sms", 3 | "version": "0.0.2", 4 | "description": "A react native android module to list/send sms.", 5 | "main": "index.android.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/msmakhlouf/react-native-android-sms.git" 12 | }, 13 | "keywords": [ 14 | "react-component", 15 | "react-native", 16 | "android" 17 | ], 18 | "author": { 19 | "name": "Mohammed Makhlouf", 20 | "email": "msmakhlouf@gmail.com" 21 | }, 22 | "peerDependencies": { 23 | "react-native": "*" 24 | }, 25 | "license": "MIT", 26 | "bugs": { 27 | "url": "https://github.com/msmakhlouf/react-native-android-sms/issues" 28 | }, 29 | "homepage": "https://github.com/msmakhlouf/react-native-android-sms#readme" 30 | } 31 | -------------------------------------------------------------------------------- /proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/mak/android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/main/java/my/qash/react/SmsModule.java: -------------------------------------------------------------------------------- 1 | package my.qash.react; 2 | 3 | 4 | import com.facebook.react.bridge.Arguments; 5 | import com.facebook.react.bridge.Callback; 6 | import com.facebook.react.bridge.NativeModule; 7 | import com.facebook.react.bridge.ReactApplicationContext; 8 | import com.facebook.react.bridge.ReactContext; 9 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 10 | import com.facebook.react.bridge.ReactMethod; 11 | import com.facebook.react.bridge.ReadableMap; 12 | import com.facebook.react.bridge.WritableMap; 13 | 14 | import android.os.Bundle; 15 | import android.widget.Toast; 16 | import android.app.LoaderManager; 17 | import android.app.PendingIntent; 18 | import android.app.PendingIntent.CanceledException; 19 | import android.content.ContentResolver; 20 | import android.content.CursorLoader; 21 | import android.content.Intent; 22 | import android.content.Loader; 23 | import android.content.Context; 24 | import android.database.Cursor; 25 | import android.net.Uri; 26 | import android.app.Activity; 27 | 28 | import android.telephony.SmsManager; 29 | import android.telephony.SmsMessage; 30 | 31 | import java.util.HashMap; 32 | import java.util.Map; 33 | 34 | import org.json.JSONArray; 35 | import org.json.JSONException; 36 | import org.json.JSONObject; 37 | 38 | 39 | /** 40 | * Created by Mohammed Makhlouf on 11/6/15. 41 | * http://qash.my 42 | */ 43 | public class SmsModule extends ReactContextBaseJavaModule /*implements LoaderManager.LoaderCallbacks*/ { 44 | // private LoaderManager mManager; 45 | private Cursor smsCursor; 46 | private Map smsList; 47 | private Map smsListBody; 48 | Activity mActivity = null; 49 | public SmsModule(ReactApplicationContext reactContext) 50 | { 51 | super(reactContext); 52 | smsList = new HashMap(); 53 | } 54 | 55 | @Override 56 | public String getName() 57 | { 58 | return "Sms"; 59 | } 60 | 61 | @ReactMethod 62 | public void list(String filter, final Callback errorCallback, final Callback successCallback) { 63 | mActivity = getCurrentActivity(); 64 | try{ 65 | JSONObject filterJ = new JSONObject(filter); 66 | String uri_filter = filterJ.has("box") ? filterJ.optString("box") : "inbox"; 67 | int fread = filterJ.has("read") ? filterJ.optInt("read") : -1; 68 | int fid = filterJ.has("_id") ? filterJ.optInt("_id") : -1; 69 | String faddress = filterJ.optString("address"); 70 | String fcontent = filterJ.optString("body"); 71 | int indexFrom = filterJ.has("indexFrom") ? filterJ.optInt("indexFrom") : 0; 72 | int maxCount = filterJ.has("maxCount") ? filterJ.optInt("maxCount") : -1; 73 | Cursor cursor = mActivity.getContentResolver().query(Uri.parse("content://sms/"+uri_filter), null, "", null, null); 74 | int c = 0; 75 | JSONArray jsons = new JSONArray(); 76 | while (cursor.moveToNext()) { 77 | boolean matchFilter = false; 78 | if (fid > -1) 79 | matchFilter = fid == cursor.getInt(cursor.getColumnIndex("_id")); 80 | else if (fread > -1) 81 | matchFilter = fread == cursor.getInt(cursor.getColumnIndex("read")); 82 | else if (faddress.length() > 0) 83 | matchFilter = faddress.equals(cursor.getString(cursor.getColumnIndex("address")).trim()); 84 | else if (fcontent.length() > 0) 85 | matchFilter = fcontent.equals(cursor.getString(cursor.getColumnIndex("body")).trim()); 86 | else { 87 | matchFilter = true; 88 | } 89 | if (matchFilter) 90 | { 91 | if (c >= indexFrom) { 92 | if (maxCount>0 && c >= indexFrom + maxCount) break; 93 | c++; 94 | // Long dateTime = Long.parseLong(cursor.getString(cursor.getColumnIndex("date"))); 95 | // String message = cursor.getString(cursor.getColumnIndex("body")); 96 | JSONObject json; 97 | json = getJsonFromCursor(cursor); 98 | jsons.put(json); 99 | 100 | } 101 | } 102 | 103 | } 104 | cursor.close(); 105 | try { 106 | successCallback.invoke(c, jsons.toString()); 107 | } catch (Exception e) { 108 | errorCallback.invoke(e.getMessage()); 109 | } 110 | } catch (JSONException e) 111 | { 112 | errorCallback.invoke(e.getMessage()); 113 | return; 114 | } 115 | } 116 | 117 | private JSONObject getJsonFromCursor(Cursor cur) { 118 | JSONObject json = new JSONObject(); 119 | 120 | int nCol = cur.getColumnCount(); 121 | String[] keys = cur.getColumnNames(); 122 | try 123 | { 124 | for (int j = 0; j < nCol; j++) 125 | switch (cur.getType(j)) { 126 | case 0: 127 | json.put(keys[j], null); 128 | break; 129 | case 1: 130 | json.put(keys[j], cur.getLong(j)); 131 | break; 132 | case 2: 133 | json.put(keys[j], cur.getFloat(j)); 134 | break; 135 | case 3: 136 | json.put(keys[j], cur.getString(j)); 137 | break; 138 | case 4: 139 | json.put(keys[j], cur.getBlob(j)); 140 | } 141 | } 142 | catch (Exception e) 143 | { 144 | return null; 145 | } 146 | 147 | return json; 148 | } 149 | 150 | @ReactMethod 151 | public void send(String addresses, String text, final Callback errorCallback, final Callback successCallback) { 152 | mActivity = getCurrentActivity(); 153 | try { 154 | JSONObject jsonObject = new JSONObject(addresses); 155 | JSONArray addressList = jsonObject.getJSONArray("addressList"); 156 | int n; 157 | if ((n = addressList.length()) > 0) { 158 | PendingIntent sentIntent = PendingIntent.getBroadcast(mActivity, 0, new Intent("SENDING_SMS"), 0); 159 | SmsManager sms = SmsManager.getDefault(); 160 | for (int i = 0; i < n; i++) 161 | { 162 | String address; 163 | if ((address = addressList.optString(i)).length() > 0) 164 | sms.sendTextMessage(address, null, text, sentIntent, null); 165 | } 166 | } else { 167 | PendingIntent sentIntent = PendingIntent.getActivity(mActivity, 0, new Intent("android.intent.action.VIEW"), 0); 168 | Intent intent = new Intent("android.intent.action.VIEW"); 169 | intent.putExtra("sms_body", text); 170 | intent.setData(Uri.parse("sms:")); 171 | try { 172 | sentIntent.send(mActivity.getApplicationContext(), 0, intent); 173 | successCallback.invoke("OK"); 174 | } 175 | catch (PendingIntent.CanceledException e) { 176 | errorCallback.invoke(e.getMessage()); 177 | return; 178 | } 179 | } 180 | return; 181 | } catch (JSONException e) { 182 | errorCallback.invoke(e.getMessage()); 183 | return; 184 | } 185 | 186 | 187 | } 188 | } 189 | 190 | 191 | 192 | 193 | 194 | -------------------------------------------------------------------------------- /src/main/java/my/qash/react/SmsPackage.java: -------------------------------------------------------------------------------- 1 | package my.qash.react; 2 | 3 | 4 | import android.app.Activity; 5 | 6 | import com.facebook.react.ReactPackage; 7 | import com.facebook.react.bridge.JavaScriptModule; 8 | import com.facebook.react.bridge.NativeModule; 9 | import com.facebook.react.bridge.ReactApplicationContext; 10 | import com.facebook.react.uimanager.ViewManager; 11 | 12 | import java.util.ArrayList; 13 | import java.util.Arrays; 14 | import java.util.Collections; 15 | import java.util.List; 16 | 17 | /** 18 | * Created by mak on 11/7/15. 19 | */ 20 | 21 | public class SmsPackage implements ReactPackage { 22 | 23 | @Override 24 | public List createNativeModules(ReactApplicationContext reactApplicationContext) { 25 | List modules = new ArrayList<>(); 26 | modules.add(new SmsModule(reactApplicationContext)); 27 | return modules; 28 | } 29 | 30 | public List> createJSModules() { 31 | return Collections.emptyList(); 32 | } 33 | 34 | @Override 35 | public List createViewManagers(ReactApplicationContext reactApplicationContext) { 36 | return Arrays.asList(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/my/qash/react/tmpwryl6c: -------------------------------------------------------------------------------- 1 | package my.qash.react; 2 | 3 | 4 | import com.facebook.react.bridge.Arguments; 5 | import com.facebook.react.bridge.Callback; 6 | import com.facebook.react.bridge.NativeModule; 7 | import com.facebook.react.bridge.ReactApplicationContext; 8 | import com.facebook.react.bridge.ReactContext; 9 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 10 | import com.facebook.react.bridge.ReactMethod; 11 | import com.facebook.react.bridge.ReadableMap; 12 | import com.facebook.react.bridge.WritableMap; 13 | 14 | import android.os.Bundle; 15 | import android.widget.Toast; 16 | import android.app.LoaderManager; 17 | import android.content.ContentResolver; 18 | import android.content.CursorLoader; 19 | import android.content.Loader; 20 | import android.content.Context; 21 | import android.database.Cursor; 22 | import android.net.Uri; 23 | import android.app.Activity; 24 | 25 | import java.util.HashMap; 26 | import java.util.Map; 27 | 28 | import org.json.JSONArray; 29 | import org.json.JSONException; 30 | import org.json.JSONObject; 31 | 32 | 33 | /** 34 | * Created by mak on 11/6/15. 35 | */ 36 | public class SmsModule extends ReactContextBaseJavaModule /*implements LoaderManager.LoaderCallbacks*/ { 37 | // private LoaderManager mManager; 38 | private Cursor smsCursor; 39 | private Map smsList; 40 | private Map smsListBody; 41 | Activity mActivity = null; 42 | public SmsModule(ReactApplicationContext reactContext, Activity activity) 43 | { 44 | super(reactContext); 45 | mActivity = activity; 46 | smsList = new HashMap(); 47 | 48 | 49 | // mManager = mActivity.getLoaderManager(); 50 | // mManager.initLoader(0, null, this); 51 | } 52 | 53 | @Override 54 | public String getName() 55 | { 56 | return "Sms"; 57 | } 58 | @ReactMethod 59 | public void show(String message, int duration) 60 | { 61 | Toast.makeText(getReactApplicationContext(), message, duration).show(); 62 | } 63 | 64 | 65 | // @Override 66 | // public Loader onCreateLoader(int id, Bundle bundle) { 67 | // String searchString = "QNB"; 68 | // return new CursorLoader(mActivity, Uri.parse("content://sms/inbox"), null, "address Like \"%" + searchString + "%\"", null, null); 69 | // } 70 | 71 | 72 | // @Override 73 | //// public void onLoadFinished(Loader loader, Cursor cursor) { 74 | //// 75 | //// long count = 0; 76 | //// while (cursor.moveToNext()) { 77 | //// Long dateTime = Long.parseLong(cursor.getString(cursor.getColumnIndex("date"))); 78 | //// String message = cursor.getString(cursor.getColumnIndex("body")); 79 | //// smsList.put(dateTime,message); 80 | //// } 81 | //// return; 82 | //// } 83 | //// @Override 84 | //// public void onLoaderReset(Loader arg0) { 85 | //// smsCursor = null; 86 | //// } 87 | 88 | @ReactMethod 89 | public void list(final Callback errorCallback, final Callback successCallback) { 90 | String searchString = "QNB"; 91 | Cursor cursor = mActivity.getContentResolver().query(Uri.parse("content://sms/inbox"), null, "address Like \"%" + searchString + "%\"", null, null); 92 | 93 | String count = "a7ay ya bo soosoo a7ay"; 94 | int c = 0; 95 | 96 | // String bigAss = ""; 97 | // WritableMap map = Arguments.createMap(); 98 | JSONArray jsons = new JSONArray(); 99 | String r = ""; 100 | while (cursor.moveToNext()) { 101 | Long dateTime = Long.parseLong(cursor.getString(cursor.getColumnIndex("date"))); 102 | String message = cursor.getString(cursor.getColumnIndex("body")); 103 | JSONObject json; 104 | if ((json = getJsonFromCursor(cursor)) == null) { 105 | 106 | } 107 | jsons.put(json); 108 | // r = "{\"timestamp\": " + dateTime + ", \"body\": \""+message+"\"}**&**"; 109 | // c++; 110 | // bigAss += r; 111 | // r = ""; 112 | // if (c==1000) 113 | // { 114 | // break; 115 | // } 116 | } 117 | // bigAss = bigAss.substring(0, bigAss.length()-5); 118 | cursor.close(); 119 | try { 120 | //WritableMap list = Arguments.createMap(); 121 | //list.putMap("sms", map); 122 | successCallback.invoke(count, c, jsons); 123 | } catch (Exception e) { 124 | errorCallback.invoke(e.getMessage()); 125 | } 126 | } 127 | 128 | private JSONObject getJsonFromCursor(Cursor cur) { 129 | JSONObject json = new JSONObject(); 130 | 131 | int nCol = cur.getColumnCount(); 132 | String[] keys = cur.getColumnNames(); 133 | try 134 | { 135 | for (int j = 0; j < nCol; j++) 136 | switch (cur.getType(j)) { 137 | case 0: 138 | json.put(keys[j], null); 139 | break; 140 | case 1: 141 | json.put(keys[j], cur.getInt(j)); 142 | break; 143 | case 2: 144 | json.put(keys[j], cur.getFloat(j)); 145 | break; 146 | case 3: 147 | json.put(keys[j], cur.getString(j)); 148 | break; 149 | case 4: 150 | json.put(keys[j], cur.getBlob(j)); 151 | } 152 | } 153 | catch (Exception e) 154 | { 155 | return null; 156 | } 157 | 158 | return json; 159 | } 160 | } 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msmakhlouf/react-native-android-sms/13fdf2db224079fa32b1abb781143da8ea89bfdf/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msmakhlouf/react-native-android-sms/13fdf2db224079fa32b1abb781143da8ea89bfdf/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msmakhlouf/react-native-android-sms/13fdf2db224079fa32b1abb781143da8ea89bfdf/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msmakhlouf/react-native-android-sms/13fdf2db224079fa32b1abb781143da8ea89bfdf/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | react 3 | 4 | -------------------------------------------------------------------------------- /src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | --------------------------------------------------------------------------------