0
次のクエリを使用して、現在の月の通話記録をデバイスから読み込みました。私は2.5〜3.5秒で完了し、sq-liteデータベース他のアプリのように通話記録をより速く読み込んで添付画像のように表示する方法
CallLogHelperクラス
public static Cursor getAllCallLogs(ContentResolver cr) {
String[] PROJECTION = new String[]{
CallLog.Calls.NUMBER,
CallLog.Calls._ID,
CallLog.Calls.CACHED_NAME,
CallLog.Calls.DATE,
CallLog.Calls.TYPE,
CallLog.Calls.DURATION};
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, -1);
Date weekBefore = calendar.getTime();
String strClause = CallLog.Calls.DATE + " >= ?";
String[] strValues = {String.valueOf(weekBefore.getTime())};
String strOrder = CallLog.Calls.DATE + " DESC limit 500";
Cursor curCalls = cr.query(CallLog.Calls.CONTENT_URI, PROJECTION, strClause,
strValues, strOrder);
return curCalls; }
から削除するようにグループ化されたログとそのidを取って、数を作っていますCallLogLoaderServicelクラス ここで私は、コールログにいくつかのデータベース操作を作っています、コードを実行するには
PHOTO_URI
で別のカーソルからロードされており、PHOTO_URI
は2/3秒かかるが、それでも2/3秒以上かかるのでは7秒かかる。
club_id
は長押しで削除しているときに私がDBからだけでなく、デバイス
club_id
の助けを借りて、特定の数のために作られた連続的な呼び出しのための共通のIDです
private void setCallLogs(Cursor curLog) {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_MORE_FAVORABLE);
logsqLiteDatabase.beginTransaction();
for (curLog.moveToLast(); !curLog.isBeforeFirst(); curLog.moveToPrevious()) {
String callNumber = curLog.getString(curLog
.getColumnIndex(CallLog.Calls.NUMBER));
callNumber = Utilities.correctNumber(callNumber);
String ids = curLog.getString(curLog
.getColumnIndex(CallLog.Calls._ID));
String name = curLog.getString(curLog
.getColumnIndex(CallLog.Calls.CACHED_NAME));
String callname = "Unknown";
try {
if (name != null)
callname = name;
} catch (Exception e) {
e.printStackTrace();
}
String callType = curLog.getString(curLog
.getColumnIndex(CallLog.Calls.TYPE));
String duration = "";
***//with pic 7 second
//withought pic uri 5/6 second***
String photoUri = "";
/* if (callNumber != null) {
photoUri = Utilities_dialer.getContactPhoto(this, callNumber);
}*/
String dateString = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
.format(new Date(Long
.parseLong(curLog.getString(curLog.getColumnIndex(CallLog.Calls.DATE)))));
if (log_db_Handler.getLogCount() == 0) {
log_db_Handler.addDialerLog(callname, callNumber, callType, ids, photoUri, dateString
, duration, String.valueOf(count), todayis, "1");
} else {
Cursor readContact = log_db_Handler.readLastCallLogs();
// if (readContact.moveToLast()) {
String phone = readContact.getString(readContact.getColumnIndex(DatabaseHandler.KEY_PH_NO));
if (phone.equals(callNumber.replace(" ", ""))) {
String type = readContact.getString(readContact.getColumnIndex(DatabaseHandler.KEY_TYPE));
club_id = readContact.getString(readContact.getColumnIndex(DialerDatabaseHandler.KEY_CLUB_ID));
int c_id = Integer.parseInt(club_id);
if (type.equals(callType)) {
log_db_Handler.addDialerLog(callname, callNumber, callType, ids, photoUri, dateString
, duration, String.valueOf(count), todayis, String.valueOf(c_id));
} else {
if (type.equals("3") && (callType.equals("10") || callType.equals("2") || callType.equals("1"))) {
c_id = c_id + 1;
log_db_Handler.addDialerLog(callname, callNumber, callType, ids, photoUri, dateString
, duration, String.valueOf(count), todayis, String.valueOf(c_id));
} else if ((type.equals("10") || type.equals("2") || type.equals("1")) && callType.equals("3")) {
c_id = c_id + 1;
log_db_Handler.addDialerLog(callname, callNumber, callType, ids, photoUri, dateString
, duration, String.valueOf(count), todayis, String.valueOf(c_id));
} else {
log_db_Handler.addDialerLog(callname, callNumber, callType, ids, photoUri, dateString
, duration, String.valueOf(count), todayis, String.valueOf(c_id));
}
}
} else {
club_id = readContact.getString(readContact.getColumnIndex(DialerDatabaseHandler.KEY_CLUB_ID));
int c_id = Integer.parseInt(club_id);
c_id = c_id + 1;
log_db_Handler.addDialerLog(callname, callNumber, callType, ids, photoUri, dateString
, duration, String.valueOf(count), todayis, String.valueOf(c_id));
}
// }
readContact.close();
}
}
logsqLiteDatabase.setTransactionSuccessful();
logsqLiteDatabase.endTransaction();
curLog.close();
endTime = System.currentTimeMillis();
long MethodeDuration = (endTime - startTime);
Log.e("MethodeDuration", "-log-" + MethodeDuration);
Intent intent = new Intent("log_updated");
sendBroadcast(intent);
smartCallPreference.setLogFirstTime("1");
}