短信存放地方:/data/data/com.android.provider/telephony/databases/telphony.db
通话记录存放地方:/data/data/com.android.provider/telephony/databases/mmssms.db
未读短信数量获取方法:
由于短消息有短信和彩信2中,所以需要查询2次。sms是短信,mms是彩信。
Cursor curMms = null; int count = 0; try { String sql = Mms.READ + " = 0 and " + Mms.MESSAGE_TYPE + " != " + PduHeaders.MESSAGE_TYPE_DELIVERY_IND// + " and " + Mms.MESSAGE_TYPE + " != " + PduHeaders.MESSAGE_TYPE_READ_ORIG_IND; curMms = contentResolver.query(Uri.parse("content://mms/inbox"), null, sql, null, null); count = curMms.getCount(); } catch (Exception e) { XLog.e(e.toString()); e.printStackTrace(); } finally { if (null != curMms) { curMms.close(); } } Cursor curSms = null; try { curSms = contentResolver.query(Uri.parse("content://sms"), null, "type = 1 and read = 0", null, null); count += curSms.getCount(); } catch (Exception e) { e.printStackTrace(); XLog.e(e.toString()); } finally { if (null != curSms) { curSms.close(); } }
未接电话数量获取方法:
未接电话需要在通话记录中查询,通话记录的类型分为三种:去电,来电,未接。
Uri uri = Calls.CONTENT_URI; String[] projects = new String[] { Calls._ID, Calls.NEW, Calls.DATE }; String selections = Calls.NEW + " = ? AND " + Calls.TYPE + " = ? AND " + Calls.IS_READ + " = ? "; String[] args = { "1", Integer.toString(Calls.MISSED_TYPE), Integer.toString(0) }; Cursor cursor = contentResolver.query(uri, projects, selections, args, null); int count = 0; if (cursor != null) { try { count = cursor.getCount(); } finally { cursor.close(); } }