oksigenia_sms 0.2.0
oksigenia_sms: ^0.2.0 copied to clipboard
Permission-minimal Android SMS sender: sends one concatenated SMS using only SEND_SMS, no READ_PHONE_STATE. Works on Android 12-17 and GrapheneOS.
example/oksigenia_sms_example.dart
// Copyright 2026 Oksigenia SL
// SPDX-License-Identifier: Apache-2.0
import 'package:oksigenia_sms/oksigenia_sms.dart';
/// Sends an emergency SMS to [contact] and prints the outcome.
///
/// The host app must already hold the runtime `SEND_SMS` permission before
/// calling this; the package requests no permissions of its own.
Future<void> sendSos(String contact) async {
const message = 'SOS - I need help.\n'
'geo:40.4168,-3.7038\n'
'https://maps.google.com/?q=40.4168,-3.7038';
// Past Android's SMS rate limit the system holds messages behind an
// Allow / Deny dialog with no timeout — check before relying on it.
final limit = await OksigeniaSms.rateLimit();
final parts = await OksigeniaSms.partCount(message);
if (!limit.allows(parts)) {
print('Android will ask for confirmation: limit '
'${limit.effectiveMaxCount}, this SOS needs $parts part(s).');
}
final result = await OksigeniaSms.send(to: contact, message: message);
switch (result.status) {
case OksigeniaSmsStatus.sent:
print('Delivered in ${result.parts} segment(s).');
case OksigeniaSmsStatus.failed:
print('Radio rejected it: ${result.error} '
'(${result.okParts}/${result.parts} ok)');
case OksigeniaSmsStatus.unknown:
// Handed to the radio; no confirmation within the timeout. Usually still
// delivered — do not re-send, or the recipient gets duplicates.
print('Submitted to the radio; no confirmation within the timeout.');
}
}