如何加载呼叫记录像其他应用程序更快,并显示像附加图像
问题描述:
我已经使用以下查询加载当前月从设备的通话记录,对我来说,它需要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; }
CallLogLoaderServicel 类我在这里做一些数据库操作与通话记录,对于执行代码,需要花费7秒的时间,
PHOTO_URI
,这是从另一个光标加载,没有PHOTO_URI
需要2/3秒,但它仍然需要2/3秒和更多。
club_id
是对于具有club_id
我想提出数帮助特定号码的连续通话常见的ID,而长按删除我以分组的日志和IDS从数据库以及从设备删除
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");
}
答
我已经尝试过,没有使用数据库,它的工作正常,并且比上次检查后的答案更快。
但我有通话记录的名称和照片uri的问题,因为缓存的数据可能不可用或在任何联系人更改后可能不会更新。他们有任何其他的方式来处理它。
private void setCallLogs(Cursor curLog) {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_MORE_FAVORABLE);
int sr_id = 0;
while (curLog.moveToNext()) {
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";
String photoUri = "";
if (name != null)
callname = name;
String callType = curLog.getString(curLog
.getColumnIndex(CallLog.Calls.TYPE));
String dateString = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
.format(new Date(Long
.parseLong(curLog.getString(curLog.getColumnIndex(CallLog.Calls.DATE)))));
//dateString = CallHistoryFragment.setdateToLog(dateString);
sr_id = sr_id + 1;
if (mainDialerhistory.size() == 0) {
club_id = 1;
count = 1;
mainDialerhistory.add(new HistoryController(ids, String.valueOf(sr_id), callname, callNumber.replace(" ", ""), dateString,
callType, "", "", count, photoUri, String.valueOf(club_id)));
} else {
count = 0;
int mainArraySize = mainDialerhistory.size() - 1;
if (mainDialerhistory.get(mainArraySize).getPhone().equals(callNumber.replace(" ", ""))) {
if (mainDialerhistory.get(mainArraySize).getcallType().equals(callType)) {
count = mainDialerhistory.get(mainArraySize).getCount() + 1;
club_id = Integer.parseInt(mainDialerhistory.get(mainArraySize).getGr_id());
mainDialerhistory.add(new HistoryController(ids, String.valueOf(sr_id), callname, callNumber.replace(" ", ""), dateString,
callType, "", "", count, photoUri, String.valueOf(club_id)));
} else {
String lastType = mainDialerhistory.get(mainArraySize).getcallType();
if (lastType.equals("3") && (callType.equals("10") || callType.equals("2") || callType.equals("1"))) {
count = 0;
club_id = Integer.parseInt(mainDialerhistory.get(mainArraySize).getGr_id()) + 1;
mainDialerhistory.add(new HistoryController(ids, String.valueOf(sr_id), callname, callNumber.replace(" ", ""), dateString,
callType, "", "", 1, photoUri, String.valueOf(club_id)));
} else if ((lastType.equals("10") || lastType.equals("2") || lastType.equals("1")) && callType.equals("3")) {
club_id = Integer.parseInt(mainDialerhistory.get(mainArraySize).getGr_id()) + 1;
mainDialerhistory.add(new HistoryController(ids, String.valueOf(sr_id), callname, callNumber.replace(" ", ""), dateString,
callType, "", "", count + 1, photoUri, String.valueOf(club_id)));
} else {
count = 0;
count = mainDialerhistory.get(mainArraySize).getCount() + 1;
club_id = Integer.parseInt(mainDialerhistory.get(mainArraySize).getGr_id());
mainDialerhistory.add(new HistoryController(ids, String.valueOf(sr_id), callname, callNumber.replace(" ", ""), dateString,
callType, "", "", count, photoUri, String.valueOf(club_id)));
}
}
} else {
club_id = Integer.parseInt(mainDialerhistory.get(mainArraySize).getGr_id()) + 1;
mainDialerhistory.add(new HistoryController(ids, String.valueOf(sr_id), callname, callNumber.replace(" ", ""), dateString,
callType, "", "", 1, photoUri, String.valueOf(club_id)));
}
}
}
curLog.close();
endTime = System.currentTimeMillis();
long MethodeDuration = (endTime - startTime);
Log.e("MethodeDuration", "-count-" + mainDialerhistory.size());
Log.e("MethodeDuration", "-log-" + MethodeDuration);
AccountController.getInstance().mAccountHistory.addAll(mainDialerhistory);
sendBroadcast(new Intent("log_updated"));
stopService(new Intent(this, CallLogIntentService.class));
}