国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

android利用ContentResolver訪問(wèn)者獲取手機(jī)短信信息

2019-12-12 03:40:08
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

利用ContentResolver訪問(wèn)者獲取手機(jī)短信信息,在此記錄一下,一遍以后查詢。

首先看一下結(jié)果,結(jié)果如下:

這里寫圖片描述

activity_message.xml類:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_message" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.android_25.MessageActivity"> <ListView  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:id="@+id/lv_message"  > </ListView></LinearLayout>

activity_xs.xml類

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_xs" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.android_25.XsActivity"><TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tv_name" /> <TextView  android:layout_width="match_parent"  android:layout_height="wrap_content"  android:id="@+id/tv_telephone"  /></LinearLayout>

MessageActivity類:

public class MessageActivity extends AppCompatActivity { private ListView lv_message; private ContentResolver cr; private ArrayList<Map<String, Object>> datalistView; @Override protected void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.activity_message);  //獲得短信的ID  lv_message = (ListView) findViewById(R.id.lv_message);  //得到訪問(wèn)者ContentResolver  cr = getContentResolver();  //定義一個(gè)接收短信的集合  datalistView = new ArrayList<>();  Uri uri = Uri.parse("content://sms/");  Cursor cursor = cr.query(uri, null, null, null, null);  while (cursor.moveToNext()) {   String body = cursor.getString(cursor.getColumnIndex("body"));   int address = cursor.getInt(cursor.getColumnIndex("address"));   //將號(hào)碼和短信內(nèi)容放入Map集合中   Map<String, Object> map = new HashMap<>();   map.put("images", address+"");   map.put("titles", body);   datalistView.add(map);  }  SimpleAdapter adapter = new SimpleAdapter(this, datalistView, R.layout.activity_xs, new String[]{"images", "titles"}, new int[]{R.id.tv_name, R.id.tv_telephone});  lv_message.setAdapter(adapter); }}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 乐清市| 辽阳县| 星子县| 永春县| 沂南县| 丘北县| 扬州市| 乌拉特前旗| 清徐县| 大同县| 泾阳县| 三原县| 衡南县| 科技| 平顺县| 白银市| 安徽省| 玉门市| 屏南县| 龙南县| 久治县| 鹤岗市| 驻马店市| 镇安县| 潼关县| 丰顺县| 炎陵县| 治县。| 岳阳市| SHOW| 双柏县| 仁布县| 乌拉特中旗| 乡宁县| 左云县| 将乐县| 大丰市| 原阳县| 株洲县| 上虞市| 萍乡市|