zoukankan      html  css  js  c++  java
  • 阅读短信

    查看收件箱中的短信

        // 查看收件箱中的短信
        public void watchInboxSMS() {
            Uri uri = Uri.parse("content://sms/inbox");
            String[] projection = new String[] { "_id", "address", "person",
                    "body", "date", "type" };
            String selection = null;
            String[] selectionArgs = null;
            String sortOrder = "date desc";
            Cursor cursor = getContentResolver().query(uri, projection, selection,
                    selectionArgs, sortOrder);
            if (!cursor.moveToFirst()) {
                return;
            }
            int i = 0;
            do {
                String name = cursor.getString(cursor.getColumnIndex("person"));
                String number = cursor.getString(cursor.getColumnIndex("address"));
                String body = cursor.getString(cursor.getColumnIndex("body"));
                String date = fmtDate(cursor.getString(cursor
                        .getColumnIndex("date")));
                String type = fmtType(cursor.getInt(cursor.getColumnIndex("type")));
                Log.i(tag, "++第" + (++i) + "短信++\nname:" + name + ",\nnumber:"
                        + number + ",\nbody:" + body + ",\ndate:" + date
                        + ",\ntype:" + type);
            } while (cursor.moveToNext());
        }

    运行结果

    11-28 15:34:15.889: I/SmsDemo(11997): ++第1短信++
    11-28 15:34:15.889: I/SmsDemo(11997): name:null,
    11-28 15:34:15.889: I/SmsDemo(11997): number:10010,
    11-28 15:34:15.889: I/SmsDemo(11997): body:温馨提示,截止11月25日,您当月套餐内流量已使用28.85MB,剩余流量11.15MB。登录联通网上营业厅www.10010.com,查询、交费、充值、方便又实惠!,
    11-28 15:34:15.889: I/SmsDemo(11997): date:2012-11-26 11:49:02,
    11-28 15:34:15.889: I/SmsDemo(11997): type:接收
    11-28 15:34:15.899: I/SmsDemo(11997): ++第2短信++
    11-28 15:34:15.899: I/SmsDemo(11997): name:null,
    11-28 15:34:15.899: I/SmsDemo(11997): number:10010,
    11-28 15:34:15.899: I/SmsDemo(11997): body:尊敬的用户,截止201210月底,您的未交使用费为15.46元,请于本月底前及时缴纳,以免产生欠费及违约金,影响您正常使用。如您确认已交费,请忽略。登陆www.10010.com,轻松交话费。,
    11-28 15:34:15.899: I/SmsDemo(11997): date:2012-11-25 11:53:22,
    11-28 15:34:15.899: I/SmsDemo(11997): type:接收
    11-28 15:34:15.899: I/SmsDemo(11997): ++第3短信++
    11-28 15:34:15.899: I/SmsDemo(11997): name:null,
    11-28 15:34:15.899: I/SmsDemo(11997): number:+861314649****,
    11-28 15:34:15.899: I/SmsDemo(11997): body:软件管理沉思录: SEI的项目管理,人际沟通,团队协作要诀 人民邮电出版社,
    11-28 15:34:15.899: I/SmsDemo(11997): date:2012-11-22 03:39:18,
    11-28 15:34:15.899: I/SmsDemo(11997): type:接收
    11-28 15:34:15.899: I/SmsDemo(11997): ++第4短信++
    11-28 15:34:15.899: I/SmsDemo(11997): name:null,
    11-28 15:34:15.899: I/SmsDemo(11997): number:106901950120,
    11-28 15:34:15.899: I/SmsDemo(11997): body:新华书店海淀桥书店-世宁大厦:47路(海淀桥东上,学院桥西下,6站),下车向东南220米 http://j.map.baidu.com/1xq4g -[百度],
    11-28 15:34:15.899: I/SmsDemo(11997): date:2012-11-20 02:35:16,
    11-28 15:34:15.899: I/SmsDemo(11997): type:接收
    11-28 15:34:15.909: I/SmsDemo(11997): ++第5短信++
    11-28 15:34:15.909: I/SmsDemo(11997): name:null,
    11-28 15:34:15.909: I/SmsDemo(11997): number:106901950120,
    11-28 15:34:15.909: I/SmsDemo(11997): body:新华书店海淀桥书店-世宁大厦:740内/983路/运通113路(海淀桥西上,学院桥西下),下车向东南200米 http://j.map.baidu.com/hvq4g -[百度],
    11-28 15:34:15.909: I/SmsDemo(11997): date:2012-11-20 02:34:58,
    11-28 15:34:15.909: I/SmsDemo(11997): type:接收

    需要注意:在运行结果中,所有短信的发件人都是null,但在1314649号码中存了名称在联系人中,想起来了,我将此号码存在SIM卡中,或许是这个原因导致发件人为null,如果将此号码存在手机上?

  • 相关阅读:
    冒泡排序、选择排序、简单二分查找
    asp.net和js读取文件的MD5值的方法
    C#对.CSV格式的文件--逗号分隔值文件 的读写操作及上传ftp服务器操作方法总结
    利用jQueryRotate旋转插件开发大转盘抽奖
    说说第三方支付接口开发及开发中遇到的坑爹问题
    浅谈程序员接私单那点事及接私单需要注意的问题
    C#微信公众号接口开发,灵活利用网页授权、带参数二维码、模板消息,提升用户体验之完成用户绑定个人微信及验证码获取
    C#.NET微信公众账号接口开发系列文章整理--微信接口开发目录,方便需要的博友查询
    C#/ASP.NET MVC微信公众号接口开发之从零开发(四) 微信自定义菜单(附源码)
    C#/ASP.NET MVC微信公众号接口开发之从零开发(三)回复消息 (附源码)
  • 原文地址:https://www.cnblogs.com/fengzhblog/p/2792747.html
Copyright © 2011-2022 走看看