我正在开发一个程序,我需要获取手机的所有电话(Recived,miss,dailed)详细信息,并希望保存在我创建的数据库中。所以我需要咨询两件事。
1-是否有可能按我的意愿去做?
2-如果是,那怎么样?
答案 0 :(得分: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);
}
希望它能满足你的需要。
答案 1 :(得分:1)
雅,有可能。请参阅以下链接。它会给出一个想法。
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
在检索完所需的所有细节后,您可以根据需要将它们插入数据库。