패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.1.0

sms_advanced

이것은 플러터용 SMS 라이브러리입니다. 안드로이드에서는 SMS 메시지 전송, 수신, SMS 메시지 쿼리, SMS 전달 상태 확인 및 연락처 정보 조회가 가능하지만, iOS 및 웹에서는 전송 기능만 지원합니다.

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 보내기
  • 안드로이드에서 SMS 수신 및 관리
  • 메시지 전달 상태 확인
  • 연락처 정보 검색 통합
  • 양방향 SMS 통신 구축

주요 기능

  • 크로스플랫폼 SMS 지원
  • 메시지 전송 및 수신(안드로이드 전용)
  • 배송 상태 추적
  • 연락처 정보 조회
  • 공개 GitHub 소스 코드

적합한 대상

  • SMS 인증이 필요한 앱
  • SMS를 활용한 고객 서비스 챗봇
  • 양방향 SMS 메시징 시스템
  • SMS 필요성이 있는 안드로이드 중심 애플리케이션
  • 오픈소스 SMS 도구를 원하는 개발자

고려 사항

  • iOS 및 웹에서 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 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.