sms 0.2.2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 92

xxhdpi

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

Designed and created by Imrul kayes

Contributions

Any contribution is welcome.

[0.2.2] - 2018-09-05

  • Update dart version

[0.2.1] - 2018-08-13

  • Fix issue with toString on error

[0.2.0] - 2018-08-09

  • Multi SIM card support

[0.1.6] - 2018-08-07

  • Fix permission error when sending SMS on Android O and above

[0.1.5] - 2018-08-06

  • Fix permission error on Android M and above

[0.1.4] - 2018-06-16

  • Error on contact lookup because of unknown size fixed

[0.1.3] - 2018-05-29

  • Error in Android 4.x because of missing permission 'READ_PROFILE' fixed
  • Updated Flutter environment sdk to ">=1.19.0 <2.0.0"
  • Example app code refactoring

[0.1.2] - 2018-05-26

  • Photo and thumbnail of a contact get loaded with the contact, no need to request them later.
  • Example app UI slightly enhanced.

[0.1.1] - 2018-05-14

  • Sms Delivery with Dart Streams and Event Channels
  • Fixed some minor errors
  • Fixed error on User Profile. The method 'getUserProfile()' will always return an instance of UserProfile even when no user profile configured in the device.
  • Fixed error in SmsThread.findContact when first message is a draft.

[0.1.0] - 2018-04-23

  • Sms Delivery

[0.0.10] - 2018-04-18

  • Automatically assign contact to created SmsThread
  • Small fix for 'date' and 'dateSent' of SmsMessage
  • Fixed error on multiple permissions requests
  • Get basic User Profile info.
  • Fix gradle build

[0.0.9] - 2018-03-15

  • backward compatibility for Contact (pull request #1 by joanpablo)

[0.0.8] - 2018-03-10

  • SmsReceiver creates all needed field
  • Add basic contact support

[0.0.7] - 2018-03-09

  • Small fix for SMS thread

[0.0.6] - 2018-03-09

  • Implementation of SMS thread

[0.0.5] - 2018-03-09

  • Support for dart < 2.0.0

[0.0.4] - 2018-03-09

  • Better query for SMS, now you can query by multiple kind instead of only one.

[0.0.3] - 2018-03-09

  • Better handling of permissions
  • Implementation of SmsQuery

[0.0.2] - 2018-03-08

  • Implementation of SmsSender

[0.0.1] - 2018-03-08

  • Implementation of SmsReceiver.

example/lib/main.dart

import 'package:flutter/widgets.dart';
import './app.dart';

void main() => runApp(new App());

Use this package as a library

1. Depend on it

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


dependencies:
  sms: ^0.2.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:sms/sms.dart';
  
Version Uploaded Documentation Archive
0.2.2 Sep 5, 2018 Go to the documentation of sms 0.2.2 Download sms 0.2.2 archive
0.2.1 Aug 13, 2018 Go to the documentation of sms 0.2.1 Download sms 0.2.1 archive
0.2.0 Aug 9, 2018 Go to the documentation of sms 0.2.0 Download sms 0.2.0 archive
0.1.6 Aug 7, 2018 Go to the documentation of sms 0.1.6 Download sms 0.1.6 archive
0.1.5 Aug 6, 2018 Go to the documentation of sms 0.1.5 Download sms 0.1.5 archive
0.1.4 Jun 16, 2018 Go to the documentation of sms 0.1.4 Download sms 0.1.4 archive
0.1.3 Jun 3, 2018 Go to the documentation of sms 0.1.3 Download sms 0.1.3 archive
0.1.1 May 16, 2018 Go to the documentation of sms 0.1.1 Download sms 0.1.1 archive
0.1.0 Apr 23, 2018 Go to the documentation of sms 0.1.0 Download sms 0.1.0 archive
0.0.10 Apr 18, 2018 Go to the documentation of sms 0.0.10 Download sms 0.0.10 archive

All 19 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
89
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
92
Learn more about scoring.

We analyzed this package on Sep 18, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.3
  • Flutter: 0.8.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

The description is too long.

Search engines will display only the first part of the description. Try to keep it under 180 characters.

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Format lib/sms.dart.

Run flutter format to format lib/sms.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8