Reputation: 761
I have been searching for this from past few days and I came to know that:
"Dual SIM is not supported in Android out of the box. It is a custom modification by manufacturers, and there is no public API to control it."
There is a solution provided in the below link but its not working on my phone Samsung Galaxy S4 Mini.
I also found this link, which I found very informative.
http://www.devlper.com/2010/06/using-android-telephonymanager/
Now I know that using the following code, I might have a chance to get lucky to make it working:
Intent callIntent = new Intent(Intent.ACTION_CALL)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
callIntent.setData(Uri.parse("tel:" + phone));
context.startActivity(callIntent);
callIntent.putExtra("com.android.phone.extra.slot", 0); //For sim 1
and
callIntent.putExtra("com.android.phone.extra.slot", 1); //For sim 2
I am not sure about this, but I have a question.
In Settings under the SIM Card Manager section, when I have to choose a preferred SIM card for Voice Call, I get four options:
When I choose Ask Always option then before making a call I am always asked for choosing a SIM Card, displayed in a Dialog Box, to make the call. My question is can I exploit this thing in my App where I press a button to make a call but it always asks me the same way it does when I chose Ask Always option.
I am sorry, I made this question lengthy, but I think it required it. Please help and big thanks in advance.
EDIT:
How can I achieve this, everytime I press any button (Kind of similar to Ask Always option in Settings) :
Upvotes: 22
Views: 54140
Reputation: 126
// SIM selection buttons
binding.sim1Button.setOnClickListener {
Log.d("DialerBottomSheet", "SIM 1 button clicked")
handleCallButtonClick(0)
}
binding.sim2Button.setOnClickListener {
Log.d("DialerBottomSheet", "SIM 2 button clicked")
handleCallButtonClick(1)
}
//Handle if the sim is not available and user initiates the call -
private fun handleCallButtonClick(simSlot: Int) {
val telephonyManager = requireContext().getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
if (isSimAvailable(telephonyManager, simSlot)) {
val number = binding.dialedNumberDisplay.text.toString() //some view where the dialed number shows
if (number.isNotEmpty()) {
Log.d("DialerBottomSheet", "Initiating check for number: $number on SIM slot: $simSlot")
checkNumberExistsAndMakeCall(number, simSlot)
} else {
Toast.makeText(context, "Please enter a number.", Toast.LENGTH_SHORT).show()
}
} else {
// SIM is not available
Toast.makeText(context, "Please Insert SIM in slot ${simSlot + 1}.", Toast.LENGTH_SHORT).show()
Log.d("DialerBottomSheet", "SIM slot $simSlot is not available.")
}
}
private fun isSimAvailable(telephonyManager: TelephonyManager, simSlot: Int): Boolean {
val simState: Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
telephonyManager.getSimState(simSlot)
} else {
if (simSlot == 0) telephonyManager.simState else TelephonyManager.SIM_STATE_UNKNOWN
}
return simState == TelephonyManager.SIM_STATE_READY
}
Upvotes: 0
Reputation: 1
I have an answer for this problem as I was looking for this option. Here are the steps:
Upvotes: -5
Reputation: 203
TelecomManager telecomManager = (TelecomManager) this.getSystemService(Context.TELECOM_SERVICE);
List<PhoneAccountHandle> phoneAccountHandleList = telecomManager.getCallCapablePhoneAccounts();
Intent intent = new Intent(Intent.ACTION_CALL).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("tel:" + number));
intent.putExtra("com.android.phone.force.slot", true);
intent.putExtra("Cdma_Supp", true);
if (simselected== 0) { //0 for sim1
for (String s : simSlotName)
intent.putExtra(s, 0); //0 or 1 according to sim.......
if (phoneAccountHandleList != null && phoneAccountHandleList.size() > 0)
intent.putExtra("android.telecom.extra.PHONE_ACCOUNT_HANDLE", phoneAccountHandleList.get(0));
} else { 1 for sim2
for (String s : simSlotName)
intent.putExtra(s, 1); //0 or 1 according to sim.......
if (phoneAccountHandleList != null && phoneAccountHandleList.size() > 1)
intent.putExtra("android.telecom.extra.PHONE_ACCOUNT_HANDLE", phoneAccountHandleList.get(1));
}
startActivity(intent);
Upvotes: 13
Reputation: 178
Code:
private final static String simSlotName[] = {
"extra_asus_dial_use_dualsim",
"com.android.phone.extra.slot",
"slot",
"simslot",
"sim_slot",
"subscription",
"Subscription",
"phone",
"com.android.phone.DialingMode",
"simSlot",
"slot_id",
"simId",
"simnum",
"phone_type",
"slotId",
"slotIdx"
};
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "any number"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("com.android.phone.force.slot", true);
intent.putExtra("Cdma_Supp", true);
//Add all slots here, according to device.. (different device require different key so put all together)
for (String s : simSlotName)
intent.putExtra(s, 0); //0 or 1 according to sim.......
//works only for API >= 21
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
intent.putExtra("android.telecom.extra.PHONE_ACCOUNT_HANDLE", (Parcelable) " here You have to get phone account handle list by using telecom manger for both sims:- using this method getCallCapablePhoneAccounts()");
context.startActivity(intent);
Upvotes: 15