SMS Send formatting
This commit is contained in:
@@ -19,20 +19,20 @@ class SmsService {
|
||||
|
||||
bool permissionGranted = await _simcards.hasPermission();
|
||||
if (!permissionGranted) {
|
||||
print("❌ Permission denied." );
|
||||
print("Permission denied." );
|
||||
return;
|
||||
}
|
||||
|
||||
List<SimCard> simCardList = await _simcards.getSimCards();
|
||||
if (simCardList.isEmpty) {
|
||||
print("❌ No SIM detected." );
|
||||
print("No SIM detected." );
|
||||
return;
|
||||
}
|
||||
|
||||
await _sendSms(destinationNumber, message, simCardList.first);
|
||||
|
||||
} catch (e) {
|
||||
print("⚠️ Error in SMS process: $e");
|
||||
print("Error in SMS process: $e");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,30 +41,22 @@ class SmsService {
|
||||
String destinationNumber, String message, SimCard selectedSim) async {
|
||||
if (Platform.isAndroid) {
|
||||
try {
|
||||
// Generate a unique ID
|
||||
var uuid = const Uuid();
|
||||
String uniqueId = uuid.v4(); // Generates a random v4 UUID
|
||||
String uniqueId = uuid.v4();
|
||||
|
||||
// The message will be the unique ID
|
||||
String smsMessage = uniqueId;
|
||||
|
||||
// flutter_sms sends the message using the device's default SMS app.
|
||||
// It does not programmatically select a SIM card. The 'selectedSim'
|
||||
// parameter from the dialog will not be used to choose the sending SIM.
|
||||
String result = await sendSMS(
|
||||
message: smsMessage,
|
||||
recipients: [destinationNumber],
|
||||
sendDirect: true, // This attempts to send directly without opening the messaging app.
|
||||
// It requires more permissions and might not work on all devices/Androidversions.
|
||||
// If false, it will open the default SMS app.
|
||||
sendDirect: true,
|
||||
);
|
||||
print("✅ SMS send result: $result. Sent via ${selectedSim.displayName} (Note: OS default SIM isused).");
|
||||
print("SMS send result: $result. Sent via ${selectedSim.displayName} (Note: OS default SIM isused).");
|
||||
|
||||
} catch (e) {
|
||||
print("⚠️ Error sending SMS: $e");
|
||||
print("Error sending SMS: $e");
|
||||
}
|
||||
} else {
|
||||
print("⚠️ SMS sending is only supported on Android.");
|
||||
print("SMS sending is only supported on Android.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user