Send SMS File created
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
<uses-permission android:name="android.permission.USE_BIOMETRIC"/>
|
||||
<uses-permission android:name="android.permission.USE_FINGERPRINT"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.SEND_SMS"/>
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
|
||||
<application
|
||||
android:label="kmobile"
|
||||
android:name="${applicationName}"
|
||||
|
||||
92
lib/api/services/send_sms_service.dart
Normal file
92
lib/api/services/send_sms_service.dart
Normal file
@@ -0,0 +1,92 @@
|
||||
// ignore_for_file: avoid_print
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:simcards/sim_card.dart';
|
||||
import 'package:simcards/simcards.dart';
|
||||
|
||||
class SmsService {
|
||||
final Simcards _simcards = Simcards();
|
||||
|
||||
Future<void> sendVerificationSms({
|
||||
required BuildContext context,
|
||||
required String destinationNumber,
|
||||
required String message,
|
||||
}) async {
|
||||
try {
|
||||
// Request permission to access SIM cards
|
||||
await _simcards.requestPermission();
|
||||
|
||||
bool permissionGranted = await _simcards.hasPermission();
|
||||
if (!permissionGranted) {
|
||||
print("❌ Permission denied.");
|
||||
return;
|
||||
}
|
||||
|
||||
List<SimCard> simCardList = await _simcards.getSimCards();
|
||||
if (simCardList.isEmpty) {
|
||||
print("❌ No SIM detected.");
|
||||
return;
|
||||
}
|
||||
|
||||
// If only one SIM card is available, send SMS directly
|
||||
if (simCardList.length == 1) {
|
||||
await _sendSms(destinationNumber, message, simCardList.first);
|
||||
return;
|
||||
}
|
||||
|
||||
// Show a dialog to let the user select a SIM card
|
||||
int? selectedSimSlot = await showDialog<int>(
|
||||
context: context,
|
||||
builder: (BuildContext dialogContext) {
|
||||
int? tempSelection;
|
||||
return AlertDialog(
|
||||
title: const Text("Select SIM to send SMS"),
|
||||
content: StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setState) {
|
||||
return DropdownButton<int>(
|
||||
hint: const Text("Choose SIM"),
|
||||
value: tempSelection,
|
||||
onChanged: (int? newValue) {
|
||||
setState(() {
|
||||
tempSelection = newValue;
|
||||
});
|
||||
},
|
||||
items: List.generate(simCardList.length, (index) {
|
||||
final sim = simCardList[index];
|
||||
return DropdownMenuItem<int>(
|
||||
value: index,
|
||||
child: Text(sim.displayName ?? "SIM ${index + 1}"),
|
||||
);
|
||||
}),
|
||||
);
|
||||
},
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(dialogContext, tempSelection);
|
||||
},
|
||||
child: const Text("OK"),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (selectedSimSlot == null) {
|
||||
print("⚠️ SIM not selected.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Send SMS using the selected SIM card
|
||||
await _sendSms(destinationNumber, message, simCardList[selectedSimSlot]);
|
||||
} catch (e) {
|
||||
print("⚠️ Error sending SMS: $e");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _sendSms(
|
||||
String destinationNumber, String message, SimCard selectedSim) async {
|
||||
// SMS Logic Here
|
||||
print("✅ SMS sent via ${selectedSim.displayName}");
|
||||
}
|
||||
}
|
||||
@@ -813,6 +813,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
simcards:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: simcards
|
||||
sha256: b621cc265ebbb3e11009ca9be67063efbc011396c4224aff8b08edaba30fa5ae
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.0.1"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
|
||||
@@ -61,6 +61,7 @@ dependencies:
|
||||
device_info_plus: ^11.3.0
|
||||
showcaseview: ^2.0.3
|
||||
package_info_plus: ^4.2.0
|
||||
simcards: ^0.0.1
|
||||
# jailbreak_root_detection: "^1.1.6"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user