如何在android中获取来电的网络(运营商)详细信息

时间:2014-11-06 05:41:33

标签: java android performance android-fragments

我希望在Android手机中获取来电详细信息,例如当有人打电话给我的Android手机获取他的号码网络(运营商)的详细信息时,如Airtel Vodefone和docomo等, 使用此方法,我获取所有详细信息,但不是运营商详细信息

public String[] callduration(){

    String callername="",type="";
    Cursor managedCursor = null;
    int number = 0,name,duration = 0,calltype = 0,date = 0;
    Uri contacts;

    try {

        contacts = CallLog.Calls.CONTENT_URI;

        managedCursor = mContext.getContentResolver().query(contacts, null, null, null, null);
        number = managedCursor.getColumnIndex( CallLog.Calls.NUMBER); 
        name= managedCursor.getColumnIndex(CallLog.Calls.CACHED_NAME);
        duration = managedCursor.getColumnIndex( CallLog.Calls.DURATION);
        calltype = managedCursor.getColumnIndex( CallLog.Calls.TYPE);
        date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
        managedCursor.moveToLast();

        callername = managedCursor.getString(name);
        if(callername == null){
             callername = managedCursor.getString(number);
        }

        if (managedCursor.getString(calltype).equalsIgnoreCase("1")) {

            type = "Incoming";

        }else if (managedCursor.getString(calltype).equalsIgnoreCase("2")){

            type = "Outgoing";

        }

    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();

    }

    return new String[]{callername,managedCursor.getString(number),managedCursor.getString(duration),
                        managedCursor.getString(date),type};
 }

1 个答案:

答案 0 :(得分:0)

官方教程,

https://developer.android.com/reference/android/telephony/TelephonyManager.html

也指这个, How to detect incoming calls, in an Android device?


getSimOperator() - 返回 SIM卡提供商的MCC + MNC(移动国家代码+移动网络代码)。


在清单文件中,

给予以下许可,

< uses-permission android:name =" android.permission.READ_PHONE_STATE" />

< uses-permission android:name =" android.permission.PROCESS_OUTGOING_CALLS" />