閱讀208 返回首頁    go 阿裏雲 go 技術社區[雲棲]


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();
	}
}



最後更新:2017-04-03 14:54:00

  上一篇:go 【轉】linux下軟件的安裝與卸載
  下一篇:go Java中異常Exception的實現的一些分析