andriod实现获取短信内容

(1)实例化(ContentResolver)

ContentResolver contentResolver = getContentResolver();
(2)(得到一同短信的url)

final String SMS_URI_INBOX = "content://sms/inbox";// 收信箱

(3)查出短信内容
String[] projection = new String[]{"_id", "address", "person", "body", "date", "type"};
Uri uri = Uri.parse(SMS_URI_INBOX);
Cursor cursor = contentResolver.query(uri, projection, null, null, "date desc");
(3)使用while循环遍历所有短信内容

while (cursor.moveToNext()) {
 Map<String, String> map  = new HashMap<>();
   String s= cursor.getString(cursor.getColumnIndex("body"));
   String c= cursor.getString(cursor.getColumnIndex("address"));
    map.put("one",c);
    map.put("two",s);
    list1.add(map);
}
simpleAdapter1.notifyDataSetChanged();
(4)(放入显示的控件)加入适配器

就ok了 ,本人使用的是listview控件

猜你喜欢

转载自blog.csdn.net/qq_37612068/article/details/56482438