访问短信代码(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 }
时间: 2024-10-27 16:26:40