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

套件詳情v0.2.4

sms

適用於Flutter應用程式的簡訊庫。它允許發送、接收、查詢簡訊訊息、簡訊傳遞狀態以及查詢聯絡人資訊。該庫為開發功能完整的簡訊應用提供了簡單友善的API。

近 30 天下載
239
喜歡數
118
Pub 分數
30

安裝套件

flutter pub add sms

套件介紹

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

Flutter 的簡訊套件提供了一個直觀的 API,可發送、接收、查詢簡訊訊息、檢查傳遞狀態,並存取聯絡人資訊。它讓開發者能以最少的設定建構功能完整的簡訊應用程式。此套件設計注重易用性,抽象化平台特定的複雜性,實現跨 Android 與 iOS 的無縫整合。該套件支援基本的通訊操作,並透過可靠的通訊功能提升應用程式的效能。

適用情境

  • 建構簡訊訊息應用
  • 實施雙重身分驗證
  • 自動化訊息傳遞
  • 整合聯絡人查詢
  • 追蹤訊息傳遞狀態
  • 建立通知系統

主要特色

  • 發送和接收簡訊
  • 查詢訊息傳遞狀態
  • 訪問聯絡人資訊
  • 簡單直覺的 API
  • 跨平台相容性
  • 對 Android 和 iOS 的支援

適合對象

  • 開發訊息應用的開發者
  • 需要簡訊驗證的應用
  • 需要自動訊息處理的工具
  • 與聯絡人整合的應用程式
  • 尋求可靠簡訊功能的專案

使用建議

  • 需要在 Android 和 iOS 上具備適當的權限
  • 僅限基本簡訊操作
  • 可能需要額外設定以處理背景訊息
  • 依賴設備級簡訊存取
  • 不適用於高容量商業訊息

原始 README

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

xxhdpi

[UNMAINTAINED] This project is unmaintained

Flutter SMS

This is an SMS library for flutter.

It only support Android for now (I can't do it for iOS because I don't own Mac).

Getting Started

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

Installation and Usage

Once you're familiar with Flutter you may install this package adding sms (0.1.4 or higher) to the dependencies list of the pubspec.yaml file as follow:

dependencies:
  flutter:
    sdk: flutter

  sms: ^0.2.0

Then run the command flutter packages get on the console.

Querying SMS messages

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

import 'package:sms/sms.dart';

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

Getting all SMS messages

List<SmsMessage> messages = await query.getAllSms;

Note: the use of await keyword means that getAllSms is resolved asynchronously and a Future is retorned.

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]
});

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

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

Getting all Threads Conversations

With SmsQuery you can also get the entire list of conversations:

List<SmsThread> threads = await query.getAllThreads;

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/contact.dart' into your dart file:

import 'package:sms/contact.dart';

void main() {
  ...
  Contact contact = threads.first.contact;
  print(contact.address);
}

Querying Contact

You can also query a contact by its address (phone number):

import 'package:sms/contact.dart';

void main() {
  ContactQuery contacts = new ContactQuery();
  Contact contact = await contacts.queryContact(someAddress());
  print(contact.fullName);
}
String getAddress() {...}

The Contact photo

You can retrieve the photo of the contact (full size or thumbnail):

...
Uint8List fullSize = contact.photo.bytes;
Uint8List thumbnail = contact.thumbnail.bytes;

User Profile

Some times it is useful to request basic info of the phone owner, like the contact photo, addresses, etc.

import 'package:sms/contact.dart';

UserProfileProvider provider = new UserProfileProvider();
UserProfile profile = await provider.getUserProfile();
print(profile.fullName);

Sending SMS

What about sending a SMS? All you have to do is to create an instance of the SmsSender class:

import 'package:sms/sms.dart';

void main() {
  SmsSender sender = new SmsSender();
  String address = someAddress();
  ...
  sender.sendSms(new SmsMessage(address, 'Hello flutter!'));
}

To be notified when the message is sent and/or delivered, you must add a listener to your message:

import 'package:sms/sms.dart';

void main() {
  SmsSender sender = new SmsSender();
  String address = someAddress();
  ...
  SmsMessage message = new SmsMessage(address, 'Hello flutter!');
  message.onStateChanged.listen((state) {
    if (state == SmsMessageState.Sent) {
      print("SMS is sent!");
    } else if (state == SmsMessageState.Delivered) {
      print("SMS is delivered!");
    }
  });
  sender.sendSms(message);
}

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:

void main() {
...
SmsSender sender = new SmsSender();
sender.onSmsDelivered.listen((SmsMessage message){
  print('${message.address} received your message.');
}));
}

You can also send with another SimCard:

void main() {
SimCardsProvider provider = new SimCardsProvider();
SimCard card = await provider.getSimCards()[0];
SmsSender sender = new SmsSender();
SmsMessage message = new SmsMessage("address", "message");
sender.sendSMS(message, simCard: card);
}

Note: Using the onSmsDelivered from the SmsSender will only notify to listeners of messages that has been sent through SmsSender.send().

Receiving SMS

If you want to be notified for incoming new messages you must subscribe to an instance of the SmsReceiver class:

import 'package:sms/sms.dart';

void main() {
  SmsReceiver receiver = new SmsReceiver();
  receiver.onSmsReceived.listen((SmsMessage msg) => print(msg.body));
}

Roadmap

  • [x] SMS Receiver
  • [x] SMS Sender
  • [x] SMS Delivery
  • [x] SMS Query
  • [x] SMS Thread
  • [ ] MMS Receiver
  • [ ] MMS Sender
  • [ ] MMS Delivery
  • [ ] MMS Query
  • [ ] Multi Sim Card
  • [x] Contact
  • [x] Contact Photo (full size, thumbnail)
  • [x] User profile (basic info)

Contributors

App logo

Designed and created by Imrul kayes

Contributions

Any contribution is welcome.

所屬分類

原始碼儲存庫

使用此套件的專案