分类: Java
2011-12-06 17:11:10
1、未读短信数
private int getMissedCallCount(Context context) {
int missedCallCount = 0;
Cursor callCursor = context.getContentResolver().query(Calls.CONTENT_URI, new String[] { Calls.NUMBER, Calls.TYPE, Calls.NEW }, null, null, Calls.DEFAULT_SORT_ORDER);
if (callCursor != null) {
while (callCursor.moveToNext()) {
int type = callCursor.getInt(callCursor.getColumnIndex(Calls.TYPE));
switch (type) {
case Calls.MISSED_TYPE:
if (callCursor.getInt(callCursor.getColumnIndex(Calls.NEW)) == 1) {
missedCallCount++;
}
break;
case Calls.INCOMING_TYPE:
case Calls.OUTGOING_TYPE:
break;
}
}
}
callCursor.close();
return missedCallCount;
}
2、未接来电数
private int getUnreadSmsCount(Context context) {
int unreadSmsCount = 0;
Cursor smsCursor = context.getContentResolver().query(Uri.parse("content://sms"), null, null, null, null);
if (smsCursor != null) {
while (smsCursor.moveToNext()) {
int type = smsCursor.getInt(smsCursor.getColumnIndex("read"));
if (type == 0) {
unreadSmsCount++;
}
}
}
smsCursor.close();
return unreadSmsCount;
}
3、权限