Checking if call being made is international

試著忘記壹切 提交于 2019-11-29 18:12:07

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