How to find target sim for an incoming call in dual sim android phone?

断了今生、忘了曾经 提交于 2020-01-24 17:24:31

问题


I am creating an android application in which I need to detect the target sim for an incoming call in dual sim phone. The Android API provides the access of only one SIM. I did googling about this but couldn't find the solution, All I found is that we can not detect the target SIM because this is depend upon the device manufactures.

Is there any API available to detect the target SIM ?


回答1:


in lollipop 22+

public class MessageReceiver extends BroadcastReceiver {
@Override
 public void onReceive(Context context, Intent intent) {  
  int slot = Integer.parseInt((String) intent.getExtras().get("slot"));
  if(slot == 0){
    // sim1
  }
  if(slot == 1){
    // sim2
  }
}

}

tested in Lenovo K3 note




回答2:


Try this...

    public class IncomingCallInterceptor extends BroadcastReceiver {
@Override
    public void onReceive(Context context, Intent intent) {
    String callingSIM = "";
    Bundle bundle = intent.getExtras();
    callingSIM =String.valueOf(bundle.getInt("simId", -1));
    if(callingSIM == "0"){
        // Incoming call from SIM1
    }
    else if(callingSIM =="1"){
        // Incoming call from SIM2
    }
    }
}


来源:https://stackoverflow.com/questions/33017254/how-to-find-target-sim-for-an-incoming-call-in-dual-sim-android-phone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!