Chinaunix首页 | 论坛 | 博客
  • 博客访问: 526312
  • 博文数量: 107
  • 博客积分: 927
  • 博客等级: 大尉
  • 技术积分: 865
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-13 17:50
文章分类

全部博文(107)

文章存档

2014年(2)

2013年(13)

2012年(16)

2011年(76)

分类: 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、权限


阅读(1050) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~