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

首頁 > 系統 > Android > 正文

android利用ContentResolver訪問者獲取手機短信信息

2019-10-23 19:45:59
字體:
來源:轉載
供稿:網友

利用ContentResolver訪問者獲取手機短信信息,在此記錄一下,一遍以后查詢。

首先看一下結果,結果如下:

android,獲取短信,獲取所有短信,獲取短信信息

activity_message.xml類:

 <LinearLayout xmlns:android/119723.html">android/233032.html">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);  //得到訪問者ContentResolver  cr = getContentResolver();  //定義一個接收短信的集合  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"));   //將號碼和短信內容放入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); }}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 绥芬河市| 土默特左旗| 泰州市| 乌拉特前旗| 铜川市| 磐安县| 高阳县| 皮山县| 同德县| 陇西县| 油尖旺区| 合作市| 招远市| 九龙城区| 青海省| 无锡市| 德阳市| 铜鼓县| 金川县| 徐州市| 孝感市| 庆阳市| 卓资县| 桐城市| 郁南县| 碌曲县| 库车县| 沐川县| 云龙县| 开阳县| 公安县| 保靖县| 南城县| 玉屏| 那坡县| 靖西县| 临猗县| 兴仁县| 含山县| 彭阳县| 慈溪市|