android - 读取传入消息,直到读取验证短信

标签 android sms broadcastreceiver intentfilter

我想在我的应用程序中添加短信阅读功能。用户在 Activity 中输入他的手机号码,然后包含一次性密码的短信从服务器发送到用户手机。我想要做的是在用户输入手机号码并期待来自服务器的传入消息后触发应用程序读取传入消息。

我在这里看到了一些这样的问题 How to read the incoming message using service in background in android?

但解决方案似乎是读取手机上的所有短信。在我的例子中,我只希望阅读功能仅在用户期待短信时开始,并在收到短信时结束。

最佳答案

检查这个告诉你如何注册接收器的答案 https://stackoverflow.com/a/7049747/774944

final String SOME_ACTION = "android.provider.Telephony.SMS_RECEIVED";
IntentFilter intentFilter = new IntentFilter(SOME_ACTION);
SMSReceiver mReceiver = new SMSReceiver();
registerReceiver(mReceiver,intentFilter);

关于android - 读取传入消息,直到读取验证短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23055884/

相关文章:

android - 引导完成后如何在 Oreo 中启动前台服务?

javascript - JS : Splitting a long string into strings with char limit while avoiding splitting words

android - 如何在 Android 手机的短信中添加超链接?

android - 报警服务不工作

android - 如何在 Android 中检测日票

android - 获取 backstack 中的最新 fragment

android - Android apk 大小会影响应用程序性能吗?

android - 如何从 Assets 文件夹或原始文件夹在android中播放视频?

android - 阻止 Android 应用程序关闭

android - 无法接收android.intent.action.USB_DGTL_MIC_PLUG