react-native - 当应用程序未运行时,如何在 ReactNative 应用程序中读取传入的短信?
问题描述
有几个 ReactNative SMS 插件可用,但大多数在应用程序处于前台时读取 SMS。当应用程序甚至没有运行时,我如何阅读短信,比如原生短信阅读器应用程序?
解决方案
I am not aware of any libraries available. But you can do as follows-
- Create a BackgroundScanService.java which is an android service, which keeps scanning the incoming sms, when it receives any sms. It broadcasts the sms.
- Create BackgroundScanModule.java, this file is the interface between your react native and Java code. Once sms is received in the broadcast receiver it passes that data to headless js. Headless js performs task when app is in the background and it performs action defined by user even when app is killed. For more info on Headless JS check https://facebook.github.io/react-native/docs/headless-js-android
I had implemented similar service for beacon scanning, you can check it here - https://medium.com/@skytreasure/react-native-beacon-scanner-when-app-is-not-running-android-172077644bc0
推荐阅读
- javascript - Highcharts:将图表旋转 90 度但也重新绘制它
- php - 使用 ionic、php 和 my sql 创建一个函数,每次在日历中的特定日期创建事件时在准确时间调用
- c# - 在 .msi 安装程序中包装 C# 应用程序
- c# - .dtbcache 文件有什么作用?
- c++ - 如何在 C++ 中增加数组值?
- python - Pandas:将列标题转换为行标签
- zlib - 如何使用 zlib 计算 CRC32-C 校验和
- node.js - 解析多部分/相关响应并将附件保存到文件
- eclipse - 如何更改 Eclipse Neon.3 中的 Google App Engine SDK 位置?
- wordpress - 全宽菜单 Wordpress