android利用ContentResolver訪問(wèn)者獲取手機(jī)短信信息
利用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í)有所幫助,也希望大家多多支持腳本之家。
- Springboot視圖解析器ViewResolver使用實(shí)例
- 淺談SpringMVC之視圖解析器(ViewResolver)
- MultipartResolver實(shí)現(xiàn)文件上傳功能
- springboot+thymeleaf國(guó)際化之LocaleResolver接口的示例
- spring-core組件詳解——PropertyResolver屬性解決器
- 剖析ASP.NET MVC的DependencyResolver組件
- Nginx DNS resolver配置實(shí)例
- Springmvc ViewResolver設(shè)計(jì)實(shí)現(xiàn)過(guò)程解析
相關(guān)文章
Android實(shí)現(xiàn)帶指示器的自動(dòng)輪播式ViewPager
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)帶指示器的自動(dòng)輪播式ViewPager的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02Android LayoutInflater.inflate源碼分析
這篇文章主要介紹了Android LayoutInflater.inflate源碼分析的相關(guān)資料,需要的朋友可以參考下2016-12-12詳解Android Libgdx中ScrollPane和Actor事件沖突問(wèn)題的解決辦法
這篇文章主要介紹了詳解Android Libgdx中ScrollPane和Actor事件沖突問(wèn)題的解決辦法的相關(guān)資料,希望通過(guò)本文能幫助到大家,需要的朋友可以參考下2017-09-09Android開(kāi)發(fā)Kotlin語(yǔ)言協(xié)程中的并發(fā)問(wèn)題和互斥鎖
Android開(kāi)發(fā)Kotlin語(yǔ)言提供了多種機(jī)制來(lái)處理并發(fā)和同步,其中包括高層次和低層次的工具,對(duì)于常規(guī)的并發(fā)任務(wù),可以利用 Kotlin 協(xié)程提供的結(jié)構(gòu)化并發(fā)方式,而對(duì)于需要更低層次的鎖定機(jī)制,可以使用Mutex(互斥鎖)來(lái)實(shí)現(xiàn)對(duì)共享資源的線程安全訪問(wèn)2024-06-06

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

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