1
The answer above answered part of my problem, only now another question has arisen.
How to check the status of SIM cards 1 and SIM 2 on a Dual SIM device?
Right now I have the solution implemented as follows:
if (phoneType == TelephonyManager.PHONE_TYPE_NONE) {
Toast.makeText(MainActivity.this, "Cartão SIM não Disponível - Não e Possível Enviar SMS", Toast.LENGTH_SHORT).show();
} else {
if (!enabled) {
// check if enabled and if not send user to the GPS settings
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
Toast.makeText(MainActivity.this, "Ative a Localização Por Favor...", Toast.LENGTH_SHORT).show();
startActivity(intent);
} else {
if (telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY) {
if (Build.VERSION.SDK_INT < 23) {
//Do not need to check the permission
//getLocation();
sendSMS();
} else {
if (checkAndRequestPermissions()) {
//If you have already permitted the permission
//getLocation();
sendSMS();
}
}
} else {
Toast.makeText(MainActivity.this, "Cartão SIM não Disponível - Não e Possível Enviar SMS", Toast.LENGTH_SHORT).show();
}
}
}
With this implementation fails on some Dual SIM devices, as I will be able to check and make conditions for cases where the SIM1 has an active card, or vice versa?
What is that "fails on some Dual SIM devices"?
– ramaral
I sent the app to a colleague with a Dual SIM device, but in which he is only using a SIM card and he says that by clicking on the button referring to the function that sends an SMS the app crashes completely. Since I don’t have the device with me, I can’t debug, but the only thing I think it might be is some issue related to being dual SIM. Once I do the SIM_STATE_READY check.
– Nuno Santos
I have an application that sends SMS and I did not need to do any kind of verification (device type or if you have SIM) just check if the SMS was sent and if not its cause. Look at this reply how this is done.
– ramaral
I did this check once my app can be used on Smartphones or Tablet’s and in the case of tablet’s without SIM, calling this feature would fail... This is the reason for checking...
– Nuno Santos
The application that I mentioned does not fail in the case of tablet’s, if the sending fails for this reason informs "Service not available". You can know if it is dual SIM using
telephonyManager..getPhoneCount()
however requires minSDK 23. The methodtelephonyManager.getSimState()
should work even on Dual SIM devices.– ramaral
I also have a Dual SIM device and can’t reproduce the error reported by it!
– Nuno Santos
So only doing debug with this device can discover the reason for the problem.
– ramaral