package com.example.missedcall;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.CallLog;
import android.provider.CallLog.Calls;
/**
* 不喜欢写博文,直接上代码,注释内容部分参考网上的材料
*
*
先贴出相关的协议:
content://sms/inbox 收件箱
content://sms/sent 已发送
content://sms/draft 草稿
content://sms/outbox 发件箱
content://sms/failed 发送失败
content://sms/queued 待发送列表
在模拟器上Outbox没有查询到数据,在模拟器上找了老半天也没找到发件箱,很郁闷。
数据库中sms相关的字段如下:
_id 一个自增字段,从1开始
thread_id 序号,同一发信人的id相同
address 发件人手机号码
person 联系人列表里的序号,陌生人为null
date 发件日期
protocol 协议,分为: 0 SMS_RPOTO, 1 MMS_PROTO
read 是否阅读 0未读, 1已读
status 状态 -1接收,0 complete, 64 pending, 128 failed
type
ALL = 0;
INBOX = 1;
SENT = 2;
DRAFT = 3;
OUTBOX = 4;
FAILED = 5;
QUEUED = 6;
body 短信内容
service_center 短信服务中心号码编号
subject 短信的主题
reply_path_present TP-Reply-Path
locked
*
*
* */
public class MissCall {
/**
* 读取未接电话号码
* */
public static int readMissCall(Context context) {
int result = 0;
Cursor cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI, new String[] {
Calls.TYPE
}, " type=? and new=?", new String[] {
Calls.MISSED_TYPE + "", "1"
}, "date desc");
if (cursor != null) {
result = cursor.getCount();
cursor.close();
}
return result;
}
/**
* 获取未读彩信数量
* */
public static int getNewMmsCount(Context context) {
int result = 0;
Cursor csr = context.getContentResolver().query(Uri.parse("content://mms/inbox"),
null, "read = 0", null, null);
if (csr != null) {
result = csr.getCount();
csr.close();
}
return result;
}
/**
* 获取未读短信数量
* */
public static int getNewSmsCount(Context context) {
int result = 0;
Cursor csr = context.getContentResolver().query(Uri.parse("content://sms"), null,
"type = 1 and read = 0", null, null);
if (csr != null) {
result = csr.getCount();
csr.close();
}
return result;
}
}
获取未读信息
最新推荐文章于 2022-04-15 12:09:24 发布