SMS Send formatting
This commit is contained in:
@@ -19,20 +19,20 @@ class SmsService {
|
|||||||
|
|
||||||
bool permissionGranted = await _simcards.hasPermission();
|
bool permissionGranted = await _simcards.hasPermission();
|
||||||
if (!permissionGranted) {
|
if (!permissionGranted) {
|
||||||
print("❌ Permission denied." );
|
print("Permission denied." );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SimCard> simCardList = await _simcards.getSimCards();
|
List<SimCard> simCardList = await _simcards.getSimCards();
|
||||||
if (simCardList.isEmpty) {
|
if (simCardList.isEmpty) {
|
||||||
print("❌ No SIM detected." );
|
print("No SIM detected." );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await _sendSms(destinationNumber, message, simCardList.first);
|
await _sendSms(destinationNumber, message, simCardList.first);
|
||||||
|
|
||||||
} catch (e) {
|
} 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 {
|
String destinationNumber, String message, SimCard selectedSim) async {
|
||||||
if (Platform.isAndroid) {
|
if (Platform.isAndroid) {
|
||||||
try {
|
try {
|
||||||
// Generate a unique ID
|
|
||||||
var uuid = const Uuid();
|
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;
|
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(
|
String result = await sendSMS(
|
||||||
message: smsMessage,
|
message: smsMessage,
|
||||||
recipients: [destinationNumber],
|
recipients: [destinationNumber],
|
||||||
sendDirect: true, // This attempts to send directly without opening the messaging app.
|
sendDirect: true,
|
||||||
// It requires more permissions and might not work on all devices/Androidversions.
|
|
||||||
// If false, it will open the default SMS app.
|
|
||||||
);
|
);
|
||||||
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) {
|
} catch (e) {
|
||||||
print("⚠️ Error sending SMS: $e");
|
print("Error sending SMS: $e");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print("⚠️ SMS sending is only supported on Android.");
|
print("SMS sending is only supported on Android.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user