欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2017年02月22日 08:43:10   作者:ly593988490  
本篇文章主要介紹了android利用ContentResolver訪問(wèn)者獲取手機(jī)短信信息,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。

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

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

這里寫(xiě)圖片描述

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í)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • android12?SD如何動(dòng)態(tài)申請(qǐng)讀寫(xiě)權(quán)限

    android12?SD如何動(dòng)態(tài)申請(qǐng)讀寫(xiě)權(quán)限

    這篇文章主要給大家介紹了關(guān)于android12?SD如何動(dòng)態(tài)申請(qǐng)讀寫(xiě)權(quán)限的相關(guān)資料,從Android?6.0開(kāi)始,權(quán)限不再是在manifest?件中粘貼?下即可,這時(shí)候權(quán)限也正式?進(jìn)?家的視野,需要的朋友可以參考下
    2023-07-07
  • Android開(kāi)發(fā)實(shí)現(xiàn)的幾何圖形工具類GeometryUtil完整實(shí)例

    Android開(kāi)發(fā)實(shí)現(xiàn)的幾何圖形工具類GeometryUtil完整實(shí)例

    這篇文章主要介紹了Android開(kāi)發(fā)實(shí)現(xiàn)的幾何圖形工具類GeometryUtil,涉及Android坐標(biāo)圖形數(shù)值運(yùn)算相關(guān)操作技巧,需要的朋友可以參考下
    2017-11-11
  • Android控件陰影顏色調(diào)整示例

    Android控件陰影顏色調(diào)整示例

    這篇文章主要介紹了Android控件陰影顏色調(diào)整示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • Android適配底部虛擬按鍵的方法詳解

    Android適配底部虛擬按鍵的方法詳解

    今天小編就為大家分享一篇Android適配底部虛擬按鍵的方法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-07-07
  • Android獲取窗體信息的Util方法

    Android獲取窗體信息的Util方法

    這篇文章主要介紹了Android獲取窗體信息的Util方法的相關(guān)資料,需要的朋友可以參考下
    2015-07-07
  • 最新評(píng)論