Reputation: 21
I know that i can detect new outgoing call by this receiver :
<receiver android:name=".NewOutgoingCallReceiver">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
And in OnReceive method i want to know which sim making this call ?
public class NewOutgoingCallReceiver extends BroadcastReceiver
{
@Override
public void onReceive( Context context, Intent intent )
{
// here i want to check which sim is making that new call
}
}
Upvotes: 0
Views: 1012
Reputation: 8553
I think this will be more correct
val SIM_SLOT_NAMES = arrayOf(
"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"
)
private fun getSimSlot(extras: Bundle?): Int {
for (name in SIM_SLOT_NAMES) {
if (extras?.containsKey(name) == true) {
return extras.getInt(name, 0)
}
}
return 0
}
// usage
getSimSlot(intent.extras)
Upvotes: 0
Reputation: 25471
The intent received by your broadcast receiver should have some extra information in the bundle, one of which is the 'slot' - meaning the SIM slot.
You can get this in your example above like this - this is for API 22 and above:
public class NewOutgoingCallReceiver extends BroadcastReceiver
{
@Override
public void onReceive( Context context, Intent intent )
{
//check which sim is making that new call
String callSlot = "";
Bundle bundle = intent.getExtras();
callSlot =String.valueOf(bundle.getInt("slot", -1));
if(callSlot == "0"){
//Call is from SIM slot0
} else if(callSlot =="1"){
//Call is from SIM slot 1
}
}
}
Upvotes: 2