Android锁屏未读短信,未接电话

由于锁屏在framework中,所以不需要添加相应的权限,如果是第三方app需要实现类似的功能,就必须声明权限。这也就是为什么Android手机的用户隐私很容易被泄漏的原因。

短信存放地方:/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();
	}
}



上一篇:《MATLAB R2012a超级学习手册》一2.4 字符串处理函数


下一篇:Matlab中Rand()函数用法