I want to retrieve the user's mobile number in Android. I am using the 'mobile_number' package to obtain dual SIM numbers from the device in Android. However, with this package, I am only able to retrieve the number for SIM 1.
I have used the following code, but I am not obtaining the number.
@override void initState() {
MobileNumber.listenPhonePermission((isPermissionGranted)
{
if (isPermissionGranted)
{ initMobileNumberState(); }
else {}
});
initMobileNumberState();
super.initState();}
Future<void> initMobileNumberState() async { if (!await MobileNumber.hasPhonePermission) { await MobileNumber.requestPhonePermission; return; }
try {
// String _mobileNumber = (await MobileNumber.mobileNumber)!;
// toastMessage(text: "Mobile : $_mobileNumber");
List<SimCard>? simCards = await MobileNumber.getSimCards;
for (SimCard simCard in simCards!)
{
print("Carrier: ${simCard.carrierName}");
print("Country: ${simCard.countryIso}");
print("Number: ${simCard.number}");
}
}
on PlatformException catch (e) {
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {});
}
I expect to retrieve both SIM numbers from the device.
I want to retrieve the user's mobile number in Android. I am using the 'mobile_number' package to obtain dual SIM numbers from the device in Android. However, with this package, I am only able to retrieve the number for SIM 1.
I have used the following code, but I am not obtaining the number.
I expect to retrieve both SIM numbers from the device.