搜尋套件、儲存庫與 APP 分類

套件詳情v1.0.7

sms_sender_background

一個用於發送簡訊訊息的 Flutter 插件,支援雙SIM卡、權限處理和多部分訊息。

Android
近 30 天下載
54
喜歡數
15
Pub 分數
160

安裝套件

flutter pub add sms_sender_background

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

sms_sender_background 是一個專為 Android 設計的 Flutter 插件,支援雙 SIM 卡、自動權限處理以及多部分訊息傳遞。它能在背景流程中實現無縫的簡訊功能,非常適合需要可靠訊息傳送而無需使用者介入的應用程式。此外,該插件與 Android 的通訊 API 無縫整合,並能處理複雜情境,例如跨多個部分的消息分割與 SIM 卡選擇。對於需要自動化或排程式簡訊通知的應用特別實用。

適用情境

  • 自動簡訊通知
  • 雙卡簡訊路由
  • 背景簡訊發送
  • 計畫訊息
  • 多部分簡訊支援
  • 基於簡訊的驗證

主要特色

  • 雙卡雙待支援
  • 自動權限管理
  • 多部分訊息處理
  • 背景執行功能
  • SIM選擇控制
  • 僅限 Android 相容性

適合對象

  • 需要自動簡訊的應用程式
  • 通知系統
  • 雙因素認證
  • 現場服務應用程式
  • 訊息工具
  • 背景任務整合

使用建議

  • 僅限 Android 平台
  • 需要執行時權限
  • 僅限簡訊功能
  • 無 iOS 支援
  • 取決於設備的通訊功能
  • 可能需要為雙卡裝置進行額外設定

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

SMS Sender Background

A Flutter plugin for sending SMS messages with support for dual SIM cards, permission handling, and multi-part messages.

Features

  • Send SMS messages from your Flutter app
  • Support for dual SIM cards (specify SIM slot)
  • Automatic permission handling (request and check SMS permissions)
  • Support for long messages (automatically splits into multi-part messages)
  • Error handling and status reporting

Getting Started

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  sms_sender_background: ^1.0.5
Android Setup

Add the following permissions to your Android Manifest (android/app/src/main/AndroidManifest.xml):

<uses-permission android:name="android.permission.SEND_SMS"/>
<!-- Optional: Required only for dual SIM support -->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

Note about READ_PHONE_STATE permission:

  • This permission is optional and only needed if you want to use dual SIM functionality
  • If not granted, the plugin will automatically fall back to using the default SIM card
  • This ensures the plugin works reliably even on devices with stricter security policies or when distributed outside Google Play
Usage
import 'package:sms_sender_background/sms_sender.dart';;

// Create an instance
final smsSender = SmsSender();

// Check SMS permission
bool hasPermission = await smsSender.checkSmsPermission();

// Request permission if needed
if (!hasPermission) {
  hasPermission = await smsSender.requestSmsPermission();
}

// Optional: Check and request READ_PHONE_STATE permission for dual SIM support
// If not granted, the plugin will use the default SIM card
bool hasPhoneStatePermission = await smsSender.checkPhoneStatePermission();
if (!hasPhoneStatePermission) {
  hasPhoneStatePermission = await smsSender.requestPhoneStatePermission();
}

// Send SMS
if (hasPermission) {
  try {
    bool success = await smsSender.sendSms(
      phoneNumber: '+1234567890',
      message: 'Hello from Flutter!',
      simSlot: 0, // Optional: specify SIM slot (0 or 1)
    );
    print('SMS sent: $success');
  } catch (e) {
    print('Error sending SMS: $e');
  }
}

Additional Features

Dual SIM Support

To send an SMS using a specific SIM card:

// Optional: Request READ_PHONE_STATE permission for dual SIM support
bool hasPhoneStatePermission = await smsSender.checkPhoneStatePermission();
if (!hasPhoneStatePermission) {
  hasPhoneStatePermission = await smsSender.requestPhoneStatePermission();
}

await smsSender.sendSms(
  phoneNumber: '+1234567890',
  message: 'Hello!',
  simSlot: 1, // Use second SIM card
);

Important Notes:

  • Dual SIM support requires the READ_PHONE_STATE permission
  • If this permission is not granted, the plugin will automatically fall back to using the default SIM card
  • This ensures compatibility across all devices, including those with stricter security policies
  • The fallback mechanism works reliably even when apps are installed from unknown sources
Long Messages

The plugin automatically handles long messages by splitting them into multiple parts:

await smsSender.sendSms(
  phoneNumber: '+1234567890',
  message: 'A very long message that will be automatically split...',
);

Error Handling

The plugin provides detailed error information through exceptions:

  • PlatformException with code "PERMISSION_DENIED" when SMS permission is not granted
  • PlatformException with code "INVALID_ARGUMENT" when phone number or message is empty
  • PlatformException with code "SMS_SEND_ERROR" when SMS sending fails

Contributing

Feel free to contribute to this project:

  1. Fork it
  2. Create your feature branch (git checkout -b feature/my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin feature/my-new-feature)
  5. Create a new Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details

所屬分類

依賴

依賴清單 1 項

  • plugin_platform_interface^2.0.2

原始碼儲存庫

使用此套件的專案

暫無相關資料。