パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.1.0

sms_advanced

これはFlutter用のSMSライブラリです。AndroidではSMSメッセージの送信・受信、SMSメッセージの照会、SMS配信状況の照会、連絡先情報の照会が可能ですが、iOSおよびWebでは送信のみをサポートしています。

AndroidiOSWeb
30日間ダウンロード
74
いいね数
100
Pub ポイント
140

パッケージをインストール

flutter pub add sms_advanced

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

sms_advanced は、Android、iOS、Web プラットフォームで SMS 機能を可能にする Flutter パッケージです。Android では、メッセージの送信・受信、メッセージの照会、配信状態の追跡、連絡先情報の取得をサポートしています。iOS および Web では、SMS メッセージの送信のみをサポートしています。このパッケージは、SMS 操作を処理するための一貫したインターフェースを提供し、基本的な SMS 統合が必要なアプリに適しています。ネイティブプラットフォーム機能に依存しており、特に Android では適切な権限が必要です。ソースコードは GitHub で公開されており、透明性とカスタマイズ性を確保しています。

用途

  • FlutterアプリからSMSを送信する
  • AndroidでSMSを受信および管理する
  • メッセージ配信状態の照会
  • 連絡先情報の取得の統合
  • 双方向SMS通信の構築

主な機能

  • クロスプラットフォームSMS対応
  • メッセージの送信と受信(Android専用)
  • 配達状態のトラッキング
  • 連絡先情報の照会
  • パブリックなGitHubソースコード

適している対象

  • SMS認証が必要なアプリ
  • SMS付きカスタマーサービスチャットボット
  • 双方向SMSメッセージングシステム
  • SMSのニーズを持つAndroid向けアプリケーション
  • オープンソースSMSツールを望む開発者

注意事項

  • iOSおよびWebでのSMS受信が制限されています
  • 完全な機能を実現するためには Android の権限が必要です
  • プラットフォーム固有の動作の違い
  • 組み込みのSMSパースまたはフィルタリングなし
  • ネイティブデバイス機能に依存します

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

sms_advanced

Buy Me A Coffee

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:

...
dependencies:
  flutter:
    sdk: flutter

  sms_advanced: ^1.0.1
...

Then run the command flutter packages get on the console.

Querying SMS messages

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

import 'package:sms_advanced/sms_advanced.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. 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:

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;

extract information

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:

import 'package:sms_advanced/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_advanced/contact.dart';

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

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_advanced/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_advanced/sms_advanced.dart';

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

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

import 'package:sms_advanced/sms_advanced.dart';

void main() {
  SmsSender sender = new SmsSender();
  String address = someAddress();
  ...
  SmsMessage message = new SmsMessage(address, 'Hello flutter world!');
  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_advanced/sms_advanced.dart';

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

Deleting SMS

Only deleting one by one is available. Don't forget to make your sms app the default sms app. blogpost guide

import 'package:sms_advanced/sms_advanced.dart';

void main() {
SmsRemover smsRemover = SmsRemover();
<boolean value> = await smsRemover.removeSmsById(sms.id, _smsThread.threadId);
}

Roadmap

IOS Web Android
SMS Sender ✓ ✓ ✓
SMS Receiver ✓
SMS Delivery ✓
SMS Query ✓
SMS Thread ✓
Contact ✓
Contact Photo (full size, thumbnail) ✓
User profile (basic info) ✓
SMS Delete One-by-one ✓

Android Integration

Activity Changes

Note that sms_advanced requires the use of a FragmentActivity instead of an Activity. To update your application:

  • If you are using FlutterActivity directly, change it to FlutterFragmentActivity in your AndroidManifest.xml.

  • If you are using a custom activity, update your MainActivity.java:

    import io.flutter.embedding.android.FlutterFragmentActivity;
    
    public class MainActivity extends FlutterFragmentActivity {
        // ...
    }
    

    or MainActivity.kt:

    import io.flutter.embedding.android.FlutterFragmentActivity
    
    class MainActivity: FlutterFragmentActivity() {
        // ...
    }
    

    to inherit from FlutterFragmentActivity.

Contributions

Any contribution is welcome.

カテゴリー

依存関係

依存関係一覧 2 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。