3

我想获得最近完成的 android 手机的电话详细信息,在获得这些详细信息后,我想在电话完成后开始我的个人应用程序的新活动。基本上我想在将此详细信息放入android手机的目录/数据库之前获取电话详细信息。如何获取此信息?

4

1 回答 1

4

首先,您需要授予从设备读取通话记录的权限。

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

现在使用此方法获取最近的通话记录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( "\nPhone Number:--- "+phNumber +" \nCall Type:--- "+dir+" \nCall Date:--- "+callDayTime+" \nCall duration in sec :--- "+callDuration );
        sb.append("\n----------------------------------");
    }
    managedCursor.close();
    call.setText(sb);
}

希望它能满足你的需要。

于 2013-07-08T05:40:49.443 回答