Check if the call is international

I want to check whether an international call or not. I have a SIM number that I get with TelephonyManager.getLine1Number (), as well as the ISO country code of the SIM card that I get with TelephonyManager.getSimCountryIso ().

In any case, can I find the country code for the call number?

0
android telephonymanager phone-call
Oct 30 '12 at 4:40
source share
1 answer

I do not think that telephonyManager.getSimCountryIso() will help you determine which country the call is made in, since it will return the country of your country .

In addition, the length of ISD codes varies from country to country. For some countries, this is 1, for some - 2, for some - 3, and for others 4. Therefore, you will need to extract / make 4 different keys of these lengths from the outgoing number, as I showed below:

Say the exit number is + 91-XXX-XXX-XXXX. then you will create 4 keys as:

  • 9 (1-digit key)
  • 91 (2-digit key)
  • 91X (3-digit key)
  • 91XX (four-digit key)

Now check if any of these 4 keys is on this list: ISO list .

[EDIT: Alternative Solution]

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

 if(outgoing-number `startswith` "00" || outgoing-number does not `startswith` your "country's-ISD-code") { //it an international call; } else { //it a domestic call; } 
0
Oct 30 '12 at 4:45
source share



All Articles