sms_advanced 是一個 Flutter 套件,可在 Android、iOS 和 Web 平台上實現簡訊功能。在 Android 上,它支援發送、接收、查詢訊息、追蹤傳遞狀態以及取得聯絡人資訊。在 iOS 和 Web 上,僅支援發送簡訊。該套件提供統一的介面來處理簡訊作業,適用於需要基本簡訊整合的應用程式。它依賴原生平台功能,並且在 Android 上需要適當的權限。原始碼公開託管在 GitHub 上,以確保透明度和可客製化。
適用情境
從 Flutter 應用發送簡訊
在 Android 上接收和管理簡訊
查詢訊息傳遞狀態
整合聯絡資訊檢索
建構雙向簡訊通訊
主要特色
跨平台簡訊支援
訊息發送和接收(僅限 Android)
配送狀態追蹤
聯絡資訊查詢
公共 GitHub 源碼
適合對象
需要簡訊驗證的應用
客服聊天機器人與簡訊
雙向簡訊訊息系統
面向 Android 的應用程式,具有簡訊需求
想要開源簡訊工具的開發者
使用建議
iOS 與網頁端簡訊接收受限
需要 Android 權限以實現完整功能
平台特定的行為差異
無內建簡訊解析或過濾
依賴於原生設備功能
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
sms_advanced
This is an SMS library for Flutter.
Getting Started
Installation and Usage
Once you're familiar with Flutter you may install this package adding sms_advanced (1.0.1 or higher) to the dependencies list of the pubspec.yaml file as follow:
Note: the use of await keyword means that getAllSms is resolved asynchronously and a Future is retorned. To use await, you must be in a function marked async.
Filtering SMS messages
The method querySms from the SmsQuery class returns a list of filtered SMS messages that match the supplied parameters. For example, for querying all the SMS messages sent and received, you could this code:
List<SmsThread> threads = await query.getAllThreads;
for( var index = num ; index >= threads.length; index-- ) {
String sendernumber = threads[index].contact?.address;
String sim = threads[index].messages.first.sim.toString();
String message = threads[index].messages.first.body;
print('sender number: $sendernumber');
print('reciever sim: $sim');
print('message: $message');
}
Getting the Contact info
Each conversation thread is related with a Contact.
The class Contact contains all the info of a thread contact (address, photo, full name).
To get access to Contact class you must import 'package:sms_advanced/contact.dart' into your dart file:
Some times it is useful to be notified of delivered messages regardless of the message. To do that you must subscribe to the onSmsDelivered of the SmsSender class instance:
voidmain() {
...
SmsSender sender = newSmsSender();
sender.onSmsDelivered.listen((SmsMessage message){
print('${message.address} received your message.');
}));
}