How do i get the carrier name of an incoming numbe

2019-01-26 00:26发布

I am able to get the carrier name using the following snippet :

TelephonyManager telephonyManager = ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE));
String operatorName = telephonyManager.getNetworkOperatorName();

It works really fine.

I am also able to get the incoming call number using the following snippet:

private final PhoneStateListener phoneStateListener = new PhoneStateListener() {

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        String callState = "UNKNOWN";
        switch (state) {
            case TelephonyManager.CALL_STATE_RINGING:
        }
    }
}

I want to find out the carrier name / service provider name of an incoming number. How can I achieve that?
Is that possible to get the incoming number's location, say, for example the country?

3条回答
2楼-- · 2019-01-26 01:07

It's not possible to get the carrier name of a whatever mobile number neither with the Android API. At least is not that easy (and you could fall into some privacy related issue i think).

Read this article for more information:

http://sms411.net/2006/07/finding-out-someones-carrier/

Of course you can try to find the original carrier (using the prefix), but that could be different from the actual one...

查看更多
欢心
3楼-- · 2019-01-26 01:12

It is not possible to retrieve the details of the carrier of a calling party programatically. Also, because of number portability, it is not possible to retrieve the carrier's name from the caller's phone number. You can, however, get the country information from the first few digits of the number. Refer List of country calling codes for more information.

查看更多
Ridiculous、
4楼-- · 2019-01-26 01:26

from API Level 22 (Andrid 5.1) This APIs are available.

SubscriptionManager subscriptionManager = (SubscriptionManager)getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);

List<SubscriptionInfo> subscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();

if (subscriptionInfoList != null && subscriptionInfoList.size() > 0) {
    for (SubscriptionInfo info : subscriptionInfoList) {
        String carrierName = info.getCarrierName().toString();
        String mobileNo = info.getNumber();
        String countyIso = info.getCountryIso();
        int dataRoaming = info.getDataRoaming();
    }
}
查看更多
登录 后发表回答