{"id":4578,"url":"https://github.com/andreyvital/react-native-android-sms-listener","last_synced_at":"2025-04-05T21:08:18.774Z","repository":{"id":57113643,"uuid":"51375623","full_name":"andreyvital/react-native-android-sms-listener","owner":"andreyvital","description":"Allows you to listen for incoming SMS messages using React Native","archived":false,"fork":false,"pushed_at":"2020-09-09T12:38:06.000Z","size":44,"stargazers_count":363,"open_issues_count":13,"forks_count":101,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-02T21:05:19.675Z","etag":null,"topics":["android","react","react-native","sms","sms-listener"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andreyvital.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-09T15:29:10.000Z","updated_at":"2025-03-21T15:27:11.000Z","dependencies_parsed_at":"2022-08-22T05:10:35.753Z","dependency_job_id":null,"html_url":"https://github.com/andreyvital/react-native-android-sms-listener","commit_stats":null,"previous_names":["centaurwarchief/react-native-android-sms-listener"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreyvital%2Freact-native-android-sms-listener","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreyvital%2Freact-native-android-sms-listener/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreyvital%2Freact-native-android-sms-listener/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreyvital%2Freact-native-android-sms-listener/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreyvital","download_url":"https://codeload.github.com/andreyvital/react-native-android-sms-listener/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271738,"owners_count":20911627,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","react","react-native","sms","sms-listener"],"created_at":"2024-01-05T20:17:16.898Z","updated_at":"2025-04-05T21:08:18.752Z","avatar_url":"https://github.com/andreyvital.png","language":"Java","funding_links":[],"categories":["Components"],"sub_categories":["System"],"readme":"## `react-native-android-sms-listener` [![react-native-android-sms-listener](https://badge.fury.io/js/react-native-android-sms-listener.svg)](https://badge.fury.io/js/react-native-android-sms-listener)\n\nA utility that allows you to listen for incoming SMS messages.\n\n### Example\n\n```JS\nimport SmsListener from 'react-native-android-sms-listener'\n\nSmsListener.addListener(message =\u003e {\n  console.info(message)\n})\n```\n\nThe contents of `message` object will be:\n\n```JS\n{\n  originatingAddress: string,\n  body: string,\n  timestamp: number\n}\n```\n\n`SmsListener#addListener` returns a `CancellableSubscription` so if you want to stop listening for incoming SMS messages you can simply `.remove` it:\n\n```JS\nlet subscription = SmsListener.addListener(...)\n\nsubscription.remove()\n```\n\nIn recent versions of Android you might also have to ask for permissions:\n\n```JS\nasync function requestReadSmsPermission() {\n  try {\n    await PermissionsAndroid.request(\n      PermissionsAndroid.PERMISSIONS.READ_SMS,\n      {\n        title: \"(...)\",\n        message: \"Why you're asking for...\"\n      }\n    );\n  } catch (err) {}\n}\n\nclass MyComponent extends Component {\n  // ...\n\n  componentDidMount() {\n    requestReadSmsPermission();\n  }\n\n  // ...\n}\n```\n\n### Example of using it for verification purposes:\n\n...and if in your sign up process you have the phone number verification step which is done by sending a code via SMS to the specified phone, you might want to verify it automatically when the user receive it \u0026mdash; pretty much like what Telegram or WhatsApp does:\n\n```JS\nlet subscription = SmsListener.addListener(message =\u003e {\n  let verificationCodeRegex = /Your verification code: ([\\d]{6})/\n\n  if (verificationCodeRegex.test(message.body)) {\n    let verificationCode = message.body.match(verificationCodeRegex)[1]\n\n    YourPhoneVerificationApi.verifyPhoneNumber(\n      message.originatingAddress,\n      verificationCode\n    ).then(verifiedSuccessfully =\u003e {\n      if (verifiedSuccessfully) {\n        subscription.remove()\n        return\n      }\n\n      if (__DEV__) {\n        console.info(\n          'Failed to verify phone `%s` using code `%s`',\n          message.originatingAddress,\n          verificationCode\n        )\n      }\n    })\n  }\n})\n```\n\nIf you're using Twilio or a similar third-party messaging service which you have a fixed phone number to deliver messages you might want to ensure that the message comes from your service by checking `message.originatingAddress`.\n\n### Installation\n\n```SH\n$ npm install --save react-native-android-sms-listener\n$ react-native link react-native-android-sms-listener\n```\n\n### Manual Installation\n\nFor a manual installation, all you need to do to use this so-called utility is:\n\n_android/settings.gradle_\n\n```Gradle\ninclude ':react-native-android-sms-listener'\nproject(':react-native-android-sms-listener').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-android-sms-listener/android')\n```\n\n_android/app/build.gradle_\n\n```Gradle\ndependencies {\n  compile project(':react-native-android-sms-listener')\n  // (...)\n}\n```\n\n_MainApplication.java_\n\n```Java\nimport com.centaurwarchief.smslistener.SmsListenerPackage;\n```\n\n```Java\n@Override\nprotected List\u003cReactPackage\u003e getPackages() {\n  return Arrays.\u003cReactPackage\u003easList(\n    new MainReactPackage(),\n    new SmsListenerPackage()\n    // (...)\n  );\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreyvital%2Freact-native-android-sms-listener","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreyvital%2Freact-native-android-sms-listener","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreyvital%2Freact-native-android-sms-listener/lists"}