我正在开发一个Android应用程序,我想将调用日志存储在数据库中。有人可以告诉我是否有可能以及如何以编程方式进行?感谢
以下是我从设备访问通话记录的代码
调用logs.java
public class Call_log extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_call_log);
Cursor mCursor = managedQuery(CallLog.Calls.CONTENT_URI, null, null,
null, null);
int number = mCursor.getColumnIndex(CallLog.Calls.NUMBER);
int date = mCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = mCursor.getColumnIndex(CallLog.Calls.DURATION);
int type = mCursor.getColumnIndex(CallLog.Calls.TYPE);
StringBuilder sb = new StringBuilder();
while (mCursor.moveToNext()) {
String phnumber = mCursor.getString(number);
String callduration = mCursor.getString(duration);
String calltype = mCursor.getString(type);
String calldate = mCursor.getString(date);
Date d = new Date(Long.valueOf(calldate));
String callTypeStr = "";
switch (Integer.parseInt(calltype)) {
case CallLog.Calls.OUTGOING_TYPE:
callTypeStr = "Outgoing";
break;
case CallLog.Calls.INCOMING_TYPE:
callTypeStr = "Incoming";
break;
case CallLog.Calls.MISSED_TYPE:
callTypeStr = "Missed";
break;
}
sb.append("Phone number " + phnumber);
sb.append(System.getProperty("line.separator"));
sb.append("Call duration " + callduration);
sb.append(System.getProperty("line.separator"));
sb.append("Call type " + callTypeStr);
sb.append(System.getProperty("line.separator"));
sb.append("Call date " + d);
sb.append("---------------------------");
sb.append(System.getProperty("line.separator"));
sb.append(System.getProperty("line.separator"));
}
TextView callDetails = (TextView) findViewById(R.id.call_logs);
callDetails.setText(sb.toString());
}
}