flutter_sms
Flutter用SMSライブラリ
- スター
- 37
- フォーク
- 41
- 最終プッシュ(UTC)
- 2020/10/09
- プロジェクト状態
- アーカイブ済み
元の README
以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。
This project is NOT maintained anymore
Took over from previous owner because the old repo isn't maintained.
Reason I took over
I am making an SMS app (that will be open source when it is more stable) and I need a good package for all the CRUD actions that I need to do with my messages.
Reason I am letting go
I wanted to maintain this flutter library since I was building my own sms application but life came in between. Sorry for not letting you know sooner. I hope someone will fork this and extend upon it, as I wanted to do.
Flutter SMS
This is an SMS library for Flutter.
It only supports Android for now. iOS and MMS is not in the scope of this project.
Extra
I have forked this repository so I can improve and add my own functionality.
Getting Started
For help getting started with Flutter, view the 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_maintained (0.2.5 or higher) to the dependencies list of the pubspec.yaml file as follow:
...
dependencies:
flutter:
sdk: flutter
sms_maintained: ^0.2.5
...
Then run the command flutter packages get on the console.
Querying SMS messages
Add the import statement for sms_maintained and create an instance of the SmsQuery class:
import 'package:sms_maintained/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. 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;
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_maintained/contact.dart' into your dart file:
import 'package:sms_maintained/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_maintained/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_maintained/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_maintained/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_maintained/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_maintained/sms.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_maintained/sms.dart';
void main() {
SmsRemover smsRemover = SmsRemover();
<boolean value> = await smsRemover.removeSmsById(sms.id, _smsThread.threadId);
}
Roadmap
- [x] SMS Receiver
- [x] SMS Sender
- [x] SMS Delivery
- [x] SMS Query
- [x] SMS Thread
- [x] Contact
- [x] Contact Photo (full size, thumbnail)
- [x] User profile (basic info)
- [x] SMS Delete One-by-one
- [ ] Improve speed.
- [ ] Add a caching layer.
- [ ] Add a helper.
- [ ] Add observables so you don't need to manually poll for changes.
- [ ] ...
MMS and iOS is not in the scope of this project. If someone wants to add the code and make a merge request for it, I am happy to include it.
If there are requests you can always make an issue. I will see what I can do.
Contributors
App logo
Designed and created by Imrul kayes
Contributions
Any contribution is welcome.
Donations
I'm a student so money isn't pouring in. Feel free to make a donation. PayPal
使用している依存関係
依存関係一覧 1 件
- flutter
{"sdk":"flutter"}
プロジェクトに合うリポジトリを選ぶには?
用途で絞り込み、開発状況を比較し、採用前に元のリポジトリで要件を確認しましょう。
- 名前・作者・説明で検索し、技術トピックで絞り込みます。
- スター、フォーク、最近のプッシュを比較します。スターは関心の目安であり、品質の保証ではありません。
- 利用前に GitHub で README、ライセンス、Issues を確認します。
情報源と管理
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗