本文主要是介绍使用ContentProvider读取手机联系人跟手机短信,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、Android使用内容提供者给我们提供了一些系统数据供我们访问,其中短信的Uri地址为:短信的Uricontent://sms/
手机联系人的Uri地址为:content://com.android.contacts/raw_contacts(获得联系人的id,姓名)
content://com.android.contacts/raw_contacts/"+id+"/data(根据联系人的id获得联系人的信息)
执行效果如下所图:
2、下面是一个简单的读取短信的例子:
如下是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_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.android_contentresolver02.MainActivity"><LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content"><Button
这篇关于使用ContentProvider读取手机联系人跟手机短信的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!