码迷,mamicode.com
首页 > 其他好文 > 详细

访问短信和写假短信

时间:2015-10-27 14:51:43      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

访问短信代码(bean类是Sms):

public List<Sms> readSMS(Context context) {
        List smsList = new ArrayList<Sms>();
        ContentResolver resolber = context.getContentResolver();
        Cursor cursor = resolber.query(Uri.parse("content://sms/"), null, null, null, null);
        if (cursor != null && cursor.getCount() > 0) {
            while (cursor.moveToNext()) {
                String address = cursor.getString(cursor.getColumnIndex("address"));
                String type = cursor.getString(cursor.getColumnIndex("type"));
                long date = cursor.getLong(cursor.getColumnIndex("date"));
                String body = cursor.getString(cursor.getColumnIndex("body"));
                String str = "";
                if (type.equals("1")) {
                    str = "发送";
                } else {
                    str = "接收";
                }
                smsList.add(new Sms(str, address, date, body));
                Log.d(TAG, "类型:" + str + "-----地址:" + address + "-----时间:" + new Date(date) + "------内容:" + body);
            }
            cursor.close();
            return smsList;
        }
        return null;
    }

写假短信代码(在短信列表中直接加入):

1 public void writeSMS() {
2         ContentResolver resolver = this.getContentResolver();
3         ContentValues values = new ContentValues();
4         values.put("address", "10086");
5         values.put("date", System.currentTimeMillis());
6         values.put("type", "1");
7         values.put("body", "送你100元话费!");
8         resolver.insert(Uri.parse("content://sms/"), values);
9     }

 

访问短信和写假短信

标签:

原文地址:http://www.cnblogs.com/zzw1994/p/4913896.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!