搜索插件、代码仓与 APP 分类

插件详情v1.0.5

flutter_sms_inbox

Flutter 短信收件箱插件(仅限 Android)。此库允许用户轻松查询收件箱消息。

Android
近 30 天下载
3650
喜欢数
92
Pub 分数
160

安装插件

flutter pub add flutter_sms_inbox

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个用于 Android 的 Flutter 插件,可轻松访问设备的短信收件箱。它允许开发者直接从用户的手机查询和检索收到的文本消息,为在应用中读取短信内容提供了一种简单的方法。专为 Android 设计,该插件利用原生 Android API 以确保可靠的消息获取。此插件非常适合需要基于短信的身份验证或消息监控的应用程序。

适合场景

  • 读取短信以进行OTP验证
  • 监控消息应用中的传入消息
  • 自动化短信数据收集
  • 与银行或服务应用程序集成

主要特点

  • 仅支持 Android
  • 用于查询收件箱的简单 API
  • 访问短信内容和元数据
  • 无需复杂的原生代码
  • 轻量且易于集成

适合对象

  • 需要短信验证的应用
  • 开发消息工具的开发者
  • 需要自动读取短信的项目
  • 面向 Android 的 Flutter 应用程序

使用建议

  • 仅适用于安卓设备
  • 需要运行时权限以访问短信
  • 可能不适用于所有Android版本
  • 用户必须明确授予短信权限
  • 仅限收件箱消息

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Flutter SMS Inbox

pub package pub points

Flutter android SMS inbox library based on Flutter SMS.

Installation

  1. Add the package to your project by the following command:
flutter pub add flutter_sms_inbox
  1. Add permission_handler package to your project because this package uses it for permission handling:
flutter pub add permission_handler
  1. Add the following permission to your AndroidManifest.xml file:
<uses-permission android:name="android.permission.READ_SMS"/>

Permission Handling

You need to request the SMS permission before dealing with the package. You can do it by using the permission_handler package. Here is an example of how to request the permission:

import 'package:permission_handler/permission_handler.dart';

Future<bool> getSmsPermission() async {
  var permissionStatus = await Permission.sms.status;

  if (permissionStatus.isGranted) {
    return true;
  } else if (permissionStatus.isDenied) {
    // We didn't ask for permission yet or the permission has been denied before but not permanently.
    if (await Permission.sms.request().isGranted) {
      return true;
    }
  } else if (permissionStatus.isPermanentlyDenied) {
    // The user opted to never again see the permission request dialog for this
    // app. The only way to change the permission's status now is to let the
    // user manually enable it in the system settings.
    openAppSettings();
  }
  return false;
}

Security notes

  • This plugin reads sensitive user data (SMS metadata and message body). Request READ_SMS only when needed and explain the purpose clearly to users.
  • Do not log, persist, or transmit SMS message content unless your app has a clear product and compliance need.
  • Handle permission denial gracefully. Calls may fail if SMS permission is revoked or restricted by device policy.
Error handling

Query calls can return structured platform errors:

  • permission_denied: READ_SMS was denied or unavailable.
  • invalid_arguments: one or more query arguments had an unexpected type or invalid value (start >= 0, count == -1 or >= 0, thread_id == -1 or >= 0, kinds must not be empty).
  • invalid_response: platform returned an unexpected payload shape.
  • query_failed: an unexpected platform failure occurred while querying SMS.

Querying SMS messages

Add the import statement for sms and create an instance of the SmsQuery class:

import 'package:flutter_sms_inbox/flutter_sms_inbox.dart';

void main() {
  SmsQuery query = SmsQuery();
}

Getting all SMS messages

List<SmsMessage> messages = await query.getAllSms;

Filtering SMS messages

The method querySms from the SmsQuery class returns a list of sms depending of the supplied parameters. For example, for querying all the sms messages sent and received write the followed code:

await query.querySms(
    kinds: [SmsQueryKind.inbox, SmsQueryKind.sent],
);

start and count are applied globally across the ordered kinds list (not per kind). For example, with kinds: [SmsQueryKind.inbox, SmsQueryKind.sent], start: 2, and count: 5, the query skips the first 2 messages across inbox then sent, and returns up to the next 5 messages from that combined ordered sequence.

For safety, queries are bounded in the Dart layer:

  • If count is omitted (or negative), the query uses a default cap of 200 messages.
  • Oversized request windows are clamped to 1000 messages before native queries are made.

The Android native layer also applies a defensive fallback cap of 1000 messages if requests arrive with unbounded or oversized values.

Privacy-safe usage patterns

  • Keep queries narrow: always set count and use address/threadId filters where possible.
  • Avoid rendering full SMS bodies by default in UI. Prefer a masked preview and add explicit user action before showing full content.
  • Do not log SMS body or sender details in production builds.
  • Do not persist or transmit SMS content unless it is strictly required and compliant with your product/privacy obligations.

You can also query all the sms messages sent and received from a specific contact:

await query.querySms(
    address: getContactAddress()
);

所属分类

源码仓库

使用此插件的项目