关于短信验证码
时间 :
2022-04-22,13:58:27
编辑 ::网站建设公司
获取短信验证码中的信息
以下是访问短信数据库的uri
content://sms/所有短信
content://sms/inbox 收件箱
content://sms/sent 已发送
content://sms/草稿
content://sms/outbox 发件箱
content://sms/发送失败
content://sms/queued to send list
×_id:短信序列号,如100
* : 通话的序号,如100,同一个手机号收发的短信序号相同
*地址:发件人地址,即手机号码,如+86
* person: 发件人,如果发件人在通讯录中,则为具体姓名,陌生人为空
* date:日期,长型,如22,可设置日期显示格式
*:协议短信、彩信
* read: 是否读0未读,1已读
*状态:短信状态-1接收,,,
* 类型:短信类型 1 接收,2 发送
* body:消息的具体内容
* :短信服务中心号码,如+86
String num="18394668672";
ContentResolver cr = getContentResolver();
String[] projection = new String[] {"address" ,"date"};//"_id", "address", "person",, "date", "type
String where = " address = "+num ;
// String where = " address = '18394668672' " ;
// String where = " date > "
// + (System.currentTimeMillis() - 10 * 60 * 1000);
Cursor cur = cr.query(SMS_INBOX, projection, where, null, "date desc");
if (null == cur)
return;
if (cur.moveToNext()) {
String date=cur.getString(cur.getColumnIndex("date"));
long l=Long.parseLong(date);
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" );
mTextView.setText(format.format(l));
//这里我是要获取自己短信服务号码中的验证码~~
// Pattern pattern = Pattern.compile(" [a-zA-Z0-9]{10}");
// Matcher matcher = pattern.matcher(body);
// if (matcher.find()) {
// String res = matcher.group().substring(1, 11);
// }
}
}
400电话优惠