Giter Club home page Giter Club logo

flutter_sms's Introduction

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

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

Contributors

App logo

Designed and created by Imrul kayes

Contributions

Any contribution is welcome.

flutter_sms's People

Contributors

babariviere avatar joanpablo avatar saifulfrank avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flutter_sms's Issues

Contact lookup appears to be failing (maybe just on M+?)

I'm writing an app to perform analytics on SMS history, and I'm unable to load contacts on my device (which is on the P beta, but I don't think that should be relevant to the issue).

When I try to run thread.findContact() it pops up the permission dialog which lets me choose to allow the app to read my contacts. That works fine. However, then it immediately throws.

Here's the stacktrace produced by the java method channel hook:

E/MethodChannel#plugins.babariviere.com/queryContactPhoto(25064): Failed to handle method call
E/MethodChannel#plugins.babariviere.com/queryContactPhoto(25064): java.lang.NegativeArraySizeException: -1
E/MethodChannel#plugins.babariviere.com/queryContactPhoto(25064): 	at com.babariviere.sms.ContactPhotoQueryHandler.queryContactPhoto(ContactPhotoQuery.java:78)
E/MethodChannel#plugins.babariviere.com/queryContactPhoto(25064): 	at com.babariviere.sms.ContactPhotoQueryHandler.handle(ContactPhotoQuery.java:46)
E/MethodChannel#plugins.babariviere.com/queryContactPhoto(25064): 	at com.babariviere.sms.ContactPhotoQuery.onMethodCall(ContactPhotoQuery.java:133)
E/MethodChannel#plugins.babariviere.com/queryContactPhoto(25064): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:191)
E/MethodChannel#plugins.babariviere.com/queryContactPhoto(25064): 	at io.flutter.view.FlutterNativeView.handlePlatformMessage(FlutterNativeView.java:136)
E/MethodChannel#plugins.babariviere.com/queryContactPhoto(25064): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.babariviere.com/queryContactPhoto(25064): 	at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#plugins.babariviere.com/queryContactPhoto(25064): 	at android.os.Looper.loop(Looper.java:160)
E/MethodChannel#plugins.babariviere.com/queryContactPhoto(25064): 	at android.app.ActivityThread.main(ActivityThread.java:6642)
E/MethodChannel#plugins.babariviere.com/queryContactPhoto(25064): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.babariviere.com/queryContactPhoto(25064): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#plugins.babariviere.com/queryContactPhoto(25064): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Which can be found here https://github.com/babariviere/flutter_sms/blob/master/android/src/main/java/com/babariviere/sms/ContactPhotoQuery.java#L78

I would try to help fix it but unfortunately I am not very experienced with the Android side of Java.

Is this perhaps my issue? If you'd like, you can see how I'm setting up the threads here: https://github.com/ArcticZeroo/sms_analytics/blob/master/lib/api/sms_manager.dart#L78

Send SMS Permisson Error

Hi, when i try to send an SMS i get this error:

AndroidRuntime(10682): Process: com.example.smsapp, PID: 10682
E/AndroidRuntime(10682): java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=2, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.example.smsapp/com.example.smsapp.MainActivity}: java.lang.SecurityException: Neither user 10279 nor current process has android.permission.READ_PHONE_STATE.

So for android 8 / Huawei Mate 9 i need to ask READ_PHONE_STATE over platform channels and then it works, but it would be better if the Plugin ask this Permission for me.

Thx

sms plugin not compatible with map_view

hello when I install sms: "^0.0.9" with map_view: "^0.0.12" I have this issue.

dependencies:
flutter:
sdk: flutter

The following adds the Cupertino Icons font to your application.

Use with the CupertinoIcons class for iOS style icons.

cupertino_icons: ^0.1.0
map_view: "^0.0.12"
sms: "^0.0.9"


FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:preDebugBuild'.

Android dependency 'com.android.support:support-v4' has different version for the compile (25.2.0) and runtime (27.1.0) classpath. You should manually set the same version via DependencyResolution

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

  • Get more help at https://help.gradle.org

BUILD FAILED in 1s
Finished with error: Gradle build failed: 1


C:\flutter\bin\flutter.bat --no-color doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.2.8, on Microsoft Windows [version 10.0.16299.309], locale fr-FR)
[√] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[√] Android Studio (version 3.0)
[√] VS Code, 64-bit edition (version 1.21.1)
[√] Connected devices (1 available)

• No issues found!
Process finished with exit code 0

Cannot send using 2nd sim slot

When sending using the 1st sim slot, the code bellow works.

SmsSender sender = new SmsSender();
SimCardsProvider provider = new SimCardsProvider();
card = await provider.getSimCards();
SmsMessage message = new SmsMessage("address", "content");
sender.sendSms(message, simCard: card.first);

However, when using card.last, in order to send via the 2nd sim slot like this:

sender.sendSms(message, simCard: card.last);

I always get this error.

E/flutter ( 6443): [ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception:
E/flutter ( 6443): PlatformException(#1, message state change error, null)
E/flutter ( 6443): #0 _rootHandleUncaughtError. (dart:async/zone.dart:1112:29)
E/flutter ( 6443): #1 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter ( 6443): #2 _startMicrotas

I am testing using Samsung Galaxy J7 Prime (SM-G610Y) with android version 6.0.1.

How to determine if message failed in sending?

I am trying how to determine if a message fails in sending, which can do so for various of reasons (no credit, bad signal and etc). However, I cannot seem to catch if the message fails when using:

SmsMessage message = new SmsMessage("address", "content");
message.onStateChanged.listen((state) {
  if (state == SmsMessageState.Sent) {
    print("SMS is sent!");
  } else if (state == SmsMessageState.Delivered) {
    print("SMS is delivered!");
  } else {
    print(state); <-- This will show "SmsMessageState.Sending"
  }
});
sender.sendSms(message);

There seems to be no enum type for SmsMessageState for "failed":

enum SmsMessageState {
  Sending,
  Sent,
  Delivered,
  None,
}

Also, even if the message fails in sending, the SmsMessageState.Sent still runs. I have not seen SmsMessageState.Delivered being triggered, even if the message is successfully sent or not.

SMS is sent but it's not stored in the Database

Hi,

I'm sending SMS successfully, they are received by the recipient. I can't however query those back.

Here's my query:

List<SmsMessage> messages = await _query.querySms(threadId: threadID, kinds: [SmsQueryKind.Inbox, SmsQueryKind.Sent], sort: true);
    print('CALLED === /// ');
    for (SmsMessage msg in _messages) {
      print(msg.body);
    }

Any ideas?

"Sent" messages are not being saved to phone when written directly [feature/smsdb]

When trying to write a message to the phone's storage, received messages are written, but sent ones are not.

Sample code:

SmsDb smsDb = SmsDb();
await smsDb.insert(SmsMessage("1234567890", "On my way home,",
          date: DateTime.fromMillisecondsSinceEpoch(1494552889918),
          dateSent: DateTime.fromMillisecondsSinceEpoch(0),
          kind: SmsMessageKind.Sent,
          read: true));
      await smsDb.insert(SmsMessage("1234567890", "Ok, see you soon!",
          date: DateTime.fromMillisecondsSinceEpoch(1494552889918),
          dateSent: DateTime.fromMillisecondsSinceEpoch(0),
          kind: SmsMessageKind.Sent,
          read: true));
      var allSms = (await SmsQuery().getAllSms);
      allSms.forEach((sms) => print(sms.toMap));
    });

output:
{address: 1234567890, body: On my way home,, _id: 1, thread_id: 77, read: true, date: 1494552889918, dateSent: 0, kind: 1}
Total number of messages written: 2
Total number of messages read back: 1.

SMS deletion

Library is great for querying, reading and sending messages but completely skipped deletion.
Also a broadcast receiver would be needed to show SMS notifications.

Could the SmsMessage.id be used to access the content provider to remove the specific message?

Also was getting a deprecated notification for the Telephony Manager, not able to reproduce. Will add when I can.

logo design contribution

Hi
I want to make a logo for this projects if you have any requirements then let me know.its totally free for open source projects.

First access error

Good afternoon. I am using this plugin to send sms. On first access, after the permission requests, when it passes the "new SmsSender ()", it gives an error and closes the system. Follow the error below. Thanks

E/AndroidRuntime(26607): java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=5, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {br.com.emdurb.areaazulorientador/br.com.emdurb.areaazulorientador.MainActivity}: java.lang.IllegalStateException: Reply already submitted E/AndroidRuntime(26607): at android.app.ActivityThread.deliverResults(Unknown Source:118) E/AndroidRuntime(26607): at android.app.ActivityThread.handleSendResult(Unknown Source:176) E/AndroidRuntime(26607): at android.app.ActivityThread.-wrap19(Unknown Source:0) E/AndroidRuntime(26607): at android.app.ActivityThread$H.handleMessage(Unknown Source:426) E/AndroidRuntime(26607): at android.os.Handler.dispatchMessage(Unknown Source:21) E/AndroidRuntime(26607): at android.os.Looper.loop(Unknown Source:139) E/AndroidRuntime(26607): at android.app.ActivityThread.main(Unknown Source:65) E/AndroidRuntime(26607): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(26607): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(Unknown Source:11) E/AndroidRuntime(26607): at com.android.internal.os.ZygoteInit.main(Unknown Source:335) E/AndroidRuntime(26607): Caused by: java.lang.IllegalStateException: Reply already submitted E/AndroidRuntime(26607): at io.flutter.view.FlutterNativeView$1.reply(FlutterNativeView.java:174) E/AndroidRuntime(26607): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:194) E/AndroidRuntime(26607): at com.ethras.simplepermissions.SimplePermissionsPlugin.onRequestPermissionsResult(SimplePermissionsPlugin.java:172) E/AndroidRuntime(26607): at io.flutter.app.FlutterPluginRegistry.onRequestPermissionsResult(FlutterPluginRegistry.java:191) E/AndroidRuntime(26607): at io.flutter.app.FlutterActivityDelegate.onRequestPermissionsResult(FlutterActivityDelegate.java:125) E/AndroidRuntime(26607): at io.flutter.app.FlutterActivity.onRequestPermissionsResult(FlutterActivity.java:133) E/AndroidRuntime(26607): at android.app.Activity.dispatchRequestPermissionsResult(Unknown Source:21) E/AndroidRuntime(26607): at android.app.Activity.dispatchActivityResult(Unknown Source:37) E/AndroidRuntime(26607): at android.app.ActivityThread.deliverResults(Unknown Source:43) E/AndroidRuntime(26607): ... 9 more

Error when trying to send message with no money on account

Hey, I've been testing out this package with a pre-paid card and at some point the money ran out on it. I didn't know it at the time, I just started getting this error:

E/flutter ( 2677): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter ( 2677): type 'PlatformException' is not a subtype of type 'String'
E/flutter ( 2677): #0      new SmsSender._private.<anonymous closure> (package:sms/sms.dart:311:71)
E/flutter ( 2677): #1      _RootZone.runUnaryGuarded (dart:async/zone.dart:1316:10)
E/flutter ( 2677): #2      _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:352:15)
E/flutter ( 2677): #3      _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:367:16)
E/flutter ( 2677): #4      _DelayedError.perform (dart:async/stream_impl.dart:589:14)
E/flutter ( 2677): #5      _StreamImplEvents.handleNext (dart:async/stream_impl.dart:694:11)
E/flutter ( 2677): #6      _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:654:7)
E/flutter ( 2677): #7      _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter ( 2677): #8      _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

Now that I know that, is there some way to catch this error so I can handle it? For eg. so that I can show a message with an error or keep the message in the queue to retry sending later.

how to listen and read a futur sms

hello, Actually when I send me an SMS I can print only the previous sms and not wait to receive the sms ( in transistion ) and print it when it's receive. how can I do that.

Querying sms by address

I think is a good idea to add the possibility to filtering/querying the SMS's collection of a specific contact (address)

Permissions error

When we are trying to request more than one request, we got an error and permission request is skipped

toString is not getting called on error objects present in print statement

Hi,

Getting following exception when trying to send message on android

E/flutter (27267): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (27267): type 'PlatformException' is not a subtype of type 'String'
E/flutter (27267): #0 new SmsSender._private. (package:sms/sms.dart:311:71)
E/flutter (27267): #1 _RootZone.runUnaryGuarded (dart:async/zone.dart:1316:10)
E/flutter (27267): #2 _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:358:15)
E/flutter (27267): #3 _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:373:16)
E/flutter (27267): #4 _DelayedError.perform (dart:async/stream_impl.dart:595:14)
E/flutter (27267): #5 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:700:11)
E/flutter (27267): #6 _PendingEvents.schedule. (dart:async/stream_impl.dart:660:7)
E/flutter (27267): #7 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (27267): #8 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

SMS package version : 0.2.0

environment details

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, v0.5.7, on Mac OS X 10.13.6 17G65, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.1)
[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
[✓] Android Studio (version 3.1)
[!] IntelliJ IDEA Community Edition (version 2018.2.1)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] Connected devices (3 available)

! Doctor found issues in 1 category.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.