android利用ContentResolver訪(fǎng)問(wèn)者獲取手機(jī)短信信息
利用ContentResolver訪(fǎng)問(wèn)者獲取手機(jī)短信信息,在此記錄一下,一遍以后查詢(xún)。
首先看一下結(jié)果,結(jié)果如下:

activity_message.xml類(lèi):
<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類(lèi)
<?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類(lèi):
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);
//得到訪(fǎng)問(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)文章
Flutter實(shí)現(xiàn)用視頻背景的登錄頁(yè)的示例代碼
這篇文章主要介紹了Flutter實(shí)現(xiàn)用視頻背景的登錄頁(yè)的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
Android?中的?Timer?和?TimerTask詳解
Timer?是?Java?中用于創(chuàng)建定時(shí)任務(wù)的類(lèi),它位于?java.util?包中,可以使用Timer來(lái)安排一次性或定期執(zhí)行的任務(wù),這篇文章主要介紹了Android?的?Timer?和?TimerTask,需要的朋友可以參考下2024-05-05
Android編程開(kāi)發(fā)實(shí)現(xiàn)TextView顯示表情圖像和文字的方法
這篇文章主要介紹了Android編程開(kāi)發(fā)實(shí)現(xiàn)TextView顯示表情圖像和文字的方法,結(jié)合實(shí)例形式分析了Android中TextView的使用技巧,需要的朋友可以參考下2015-12-12
Android中的常用尺寸單位(dp、sp)快速入門(mén)教程
本文詳細(xì)介紹了Android開(kāi)發(fā)中常用尺寸單位的含義,重點(diǎn)講解了sp與dp這兩個(gè)尺寸單位的本質(zhì)以及它們與px的換算公式,文中介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-05-05
Android如何使用RecyclerView打造首頁(yè)輪播圖
這篇文章主要為大家詳細(xì)介紹了Android如何使用RecyclerView打造首頁(yè)輪播圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02
Android的Launcher啟動(dòng)器中添加快捷方式及小部件實(shí)例
這篇文章主要介紹了在Android的Launcher啟動(dòng)器中添加快捷方式及窗口小部件的方法,包括在自己的應(yīng)用程序中添加窗口小部件AppWidget的例子,需要的朋友可以參考下2016-02-02
Android中封裝RecyclerView實(shí)現(xiàn)添加頭部和底部示例代碼
這篇文章主要給大家介紹了關(guān)于Android中封裝RecyclerView實(shí)現(xiàn)添加頭部和底部的相關(guān)資料,網(wǎng)上這方面的資料很多,但都不是自己需要的,索性自己寫(xiě)一個(gè)分享出來(lái)供大家參考學(xué)習(xí),需要的朋友們下面隨著小編一起來(lái)學(xué)習(xí)學(xué)習(xí)吧。2017-08-08
Android ListView優(yōu)化之提高android應(yīng)用效率
android listview優(yōu)化做的好是提高androoid應(yīng)用效率的前提條件,本文給大家介紹Android ListView優(yōu)化之提高android應(yīng)用效率,對(duì)android listview優(yōu)化相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2015-12-12
Android實(shí)現(xiàn)圖片輪播切換實(shí)例代碼
利用Android的ViewFlipper和AnimationUtils實(shí)現(xiàn)圖片帶有動(dòng)畫(huà)的輪播切換,其中當(dāng)點(diǎn)擊“上一張”圖片時(shí),切換到上一張圖片;當(dāng)點(diǎn)擊“下一張”圖片時(shí),切換到下一張圖片,本文給大家介紹Android實(shí)現(xiàn)圖片輪播切換實(shí)例代碼,需要的朋友參考下2015-12-12

