Checking if call being made is international

∥☆過路亽.° 提交于 2019-11-28 12:27:46

问题


I'd like to check if a call being made is international or not. I have the SIM number which I obtain by using TelephonyManager.getLine1Number() and also the Country code ISO of the SIM Card which I obtain using TelephonyManager.getSimCountryIso().

Is there anyway I can find the country code of the number to which the call is being made?


回答1:


I don't think telephonyManager.getSimCountryIso() would help you determine 'to which country the call is being made' as it will return your country's ISO.

Moreover, length of ISD codes vary across countries. For some countries it is 1, for some it's 2, for some it's 3 and for others it's 4. So you will need to extract/make 4 different keys of these lengths from the outgoing number as I have shown below:

Say the out going number is +91-XXX-XXX-XXXX. then you'll create 4 keys as:

  1. 9 (1 digit key)
  2. 91 (2 digit key)
  3. 91X (3 digit key)
  4. 91XX (4 digit key)

Now check if any of these 4 keys is present in this list: ISO List.

[EDIT: Alternative Solution]

Again, if you only need to determine if the call being made is international or not then you can simply check for below condition:

if(outgoing-number `startswith` "00" || outgoing-number does not `startswith` your "country's-ISD-code") {
    //it's an international call;
} else {
    //it's a domestic call;
}


来源:https://stackoverflow.com/questions/13132724/checking-if-call-being-made-is-international

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