• Android 通话记录分析


    http://stackoverflow.com/questions/6786666/how-do-i-access-call-log-for-android

    http://android2011dev.blogspot.in/2011/08/get-android-phone-call-historylog.html

    How do I access call log for android?

    http://developer.android.com/reference/android/provider/CallLog.Calls.html

    First you need to give the permission to read call logs from the device.

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

    Now use this method to get the recent call logs getCallDetails()

    private void getCallDetails() {
    
        StringBuffer sb = new StringBuffer();
        Cursor managedCursor = managedQuery( CallLog.Calls.CONTENT_URI,null, null,null, null);
        int number = managedCursor.getColumnIndex( CallLog.Calls.NUMBER ); 
        int type = managedCursor.getColumnIndex( CallLog.Calls.TYPE );
        int date = managedCursor.getColumnIndex( CallLog.Calls.DATE);
        int duration = managedCursor.getColumnIndex( CallLog.Calls.DURATION);
        sb.append( "Call Details :");
    
        while ( managedCursor.moveToNext() ) {
            String phNumber = managedCursor.getString( number );
            String callType = managedCursor.getString( type );
            String callDate = managedCursor.getString( date );
            Date callDayTime = new Date(Long.valueOf(callDate));
            String callDuration = managedCursor.getString( duration );
            String dir = null;
            int dircode = Integer.parseInt( callType );
    
            switch( dircode ) {
                case CallLog.Calls.OUTGOING_TYPE:
                    dir = "OUTGOING";
                break;
    
                case CallLog.Calls.INCOMING_TYPE:
                    dir = "INCOMING";
                break;
    
                case CallLog.Calls.MISSED_TYPE:
                    dir = "MISSED";
                break;
            }
    
            sb.append( "
    Phone Number:--- "+phNumber +" 
    Call Type:--- "+dir+" 
    Call Date:--- "+callDayTime+" 
    
    Call duration in sec :--- "+callDuration );
    sb.append(" ----------------------------------");
        }
        managedCursor.close();
        call.setText(sb);
    }

    private static String getCallDetails(Context context) {
        StringBuffer stringBuffer = new StringBuffer();
        Cursor cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI,
                null, null, null, CallLog.Calls.DATE + " DESC");
        int number = cursor.getColumnIndex(CallLog.Calls.NUMBER);
        int type = cursor.getColumnIndex(CallLog.Calls.TYPE);
        int date = cursor.getColumnIndex(CallLog.Calls.DATE);
        int duration = cursor.getColumnIndex(CallLog.Calls.DURATION);       
        while (cursor.moveToNext()) {
            String phNumber = cursor.getString(number);
            String callType = cursor.getString(type);
            String callDate = cursor.getString(date);
            Date callDayTime = new Date(Long.valueOf(callDate));
            String callDuration = cursor.getString(duration);
            String dir = null;
            int dircode = Integer.parseInt(callType);
            switch (dircode) {
            case CallLog.Calls.OUTGOING_TYPE:
                dir = "OUTGOING";
                break;
            case CallLog.Calls.INCOMING_TYPE:
                dir = "INCOMING";
                break;
    
            case CallLog.Calls.MISSED_TYPE:
                dir = "MISSED";
                break;
            }
            stringBuffer.append("
    Phone Number:--- " + phNumber + " 
    Call Type:--- "
                    + dir + " 
    Call Date:--- " + callDayTime
                    + " 
    Call duration in sec :--- " + callDuration);
            stringBuffer.append("
    ----------------------------------");
        }
        cursor.close();
        return stringBuffer.toString();
    }
  • 相关阅读:
    程序猿神吐槽,说出那些苦逼的日子!
    java设计模式演示样例
    DP Leetcode
    标准差(standard deviation)和标准误差(standard error)你能解释清楚吗?
    移动开发 Native APP、Hybrid APP和Web APP介绍
    Oracle cloud control 12c 的启动与关闭
    Ubuntu文件的复制、移动和删除命令
    Android中集成第三方库的方法和问题
    腾讯QQ企业邮箱POP3/SMTP设置
    又发现支付宝和淘宝的设计漏洞
  • 原文地址:https://www.cnblogs.com/shangdawei/p/4465594.html
Copyright © 2020-2023  润新知