在之前项目中有用到关于获取手机联系人的部分,闲置就想和大家分享一下,话不多说,上代码:
java部分:
包com.example.content; 进口android.content.ContentResolver; 进口android.database.Cursor; 进口android.net.Uri; 进口android.support.v7.app.AppCompatActivity; 进口android.os.Bundle; 进口android.util.Log; 进口android.view.View; 公开课MainActivity延伸AppCompatActivity { 私人ContentResolver铬; @Override 保护空白> & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; LinearLayout & lt; xmlns: android=" http://schemas.android.com/apk/res/android " xmlns:应用=" http://schemas.android.com/apk/res-auto " xmlns:工具=" http://schemas.android.com/tools " android: layout_width=癿atch_parent” android: layout_height=" match_parent "工具:上下文=癱om.example.content.MainActivity”比; & lt;按钮 android: layout_width=" wrap_content " android: layout_height=" wrap_content " android:文本="获取手机联系人” android: onClick=" getContacts "/比; & lt;/LinearLayout> >之前在需要获取系统的东西的时候一定不要忘记给权限啊
AndroidManifest。xml部分:
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt;清单xmlns: android=" http://schemas.android.com/apk/res/android "包=癱om.example.content”比; & lt; !——获取手机的联系人——比; & lt; uses-permission android: name=" android.permission.READ_CONTACTS祝辞& lt;/uses-permission> & lt;应用android: allowBackup=" true " android:图标=癅mipmap/ic_launcher” android: label=" @string/app_name " android: roundIcon=癅mipmap/ic_launcher_round” android: supportsRtl=" true " android:主题=癅style/AppTheme”比; & lt;活动android: name=?MainActivity”比; & lt; intent-filter> & lt;行动android: name=" android.intent.action.MAIN "/比; & lt;类别android: name=" android.intent.category.LAUNCHER "/比; & lt;/intent-filter> & lt;/activity> & lt;/application> & lt;/manifest> >之前以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
安卓ContentProvider实现获取手机联系人功能