检查是否调用正在为国际国际

2023-09-04 04:40:46 作者:碾压我心

我要检查,如果一个呼叫正在为国际或不是。我有我获得通过TelephonyManager.getLine1Number的SIM卡号码(),也是国家code中的SIM卡,我得到使用TelephonyManager.getSimCountryIso()ISO。

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().

反正是有,我可以找到号码的国家code正在取得到的电话吗?

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

推荐答案

我不认为 telephonyManager.getSimCountryIso()将帮助您确定哪个国家的呼叫正在取得',因为它会返回您国家的ISO。

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.

此外,政府新闻处codeS的长度不同国家而有所不同。对于一些国家来说是1,对一些人来说是2,对一些人来说是3和他人是4。所以你需要解压/让4个不同的呼出号码,这些长度的密钥,因为我已经证明如下:

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:

说出了去电号码为+ 91-XXX-XXX-XXXX。 那么您将创建4个按键为:

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

9 (1位密钥) 91 (2位密钥) 91X (3数字键) 91XX (4数字键) 9 (1 digit key) 91 (2 digit key) 91X (3 digit key) 91XX (4 digit key)

现在检查是否有这4个按键为present在此列表中:的 ISO列表。

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

同样,如果你只需要确定该呼叫正在为国际或没有,那么你可以简单地检查以下条件:

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;
}