百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

react-native-android-sms-listener

> 前端框架
开源

允许您使用 React Native 监听来自的短信消息

374 stars0 点赞4 次浏览
访问官网GitHub

工具介绍

允许您使用 React Native 监听来自的短信消息

react-native-android-sms-listener

A utility that allows you to listen for incoming SMS messages.

Example

javascript
import SmsListener from 'react-native-android-sms-listener'

SmsListener.addListener(message => {
  console.info(message)
})

The contents of message object will be:

javascript
{
  originatingAddress: string,
  body: string,
  timestamp: number
}

SmsListener#addListener returns a CancellableSubscription so if you want to stop listening for incoming SMS messages you can simply .remove it:

javascript
let subscription = SmsListener.addListener(...)

subscription.remove()

In recent versions of Android you might also have to ask for permissions:

javascript
async function requestReadSmsPermission() {
  try {
    await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.READ_SMS,
      {
        title: "(...)",
        message: "Why you're asking for..."
      }
    );
  } catch (err) {}
}

class MyComponent extends Component {
  // ...

  componentDidMount() {
    requestReadSmsPermission();
  }

  // ...
}

Example of using it for verification purposes:

...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 — pretty much like what Telegram or WhatsApp does:

…

If 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.

Installation

bash
$ npm install --save react-native-android-sms-listener
$ react-native link react-native-android-sms-listener

Manual Installation

For a manual installation, all you need to do to use this so-called utility is:

android/settings.gradle

gradle
include ':react-native-android-sms-listener'
project(':react-native-android-sms-listener').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-android-sms-listener/android')

android/app/build.gradle

gradle
dependencies {
  compile project(':react-native-android-sms-listener')
  // (...)
}

MainApplication.java

java
import com.centaurwarchief.smslistener.SmsListenerPackage;
java
@Override
protected List getPackages() {
  return Arrays.asList(
    new MainReactPackage(),
    new SmsListenerPackage()
    // (...)
  );
}

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Javaandroidreactreact-nativesms

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架