android - 如何获取Android设备上的用户个人资料

标签 android android-contacts contactscontract accountmanager google-account

我希望能够自动将信息输入到创建帐户表单中,并根据用户已输入到设备中的信息(例如姓名、电子邮件地址、电话号码)提出可能性建议。我需要一种与 API 级别 8 兼容的方法。

最佳答案

我找到了Roman Nurik's answer一个非常相似的答案,因此我的答案是基于他的答案。这是gist of my answer 。您需要向 AndroidManifest.xml 添加权限和功能才能访问用户的个人资料:

<!-- Allows application to view phone state like using readLine1Number() -->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<!-- Required to access the Contacts Provider and user profile -->
<uses-permission android:name="android.permission.READ_PROFILE"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>

<!-- Allows the application to use telephony to get the devices phone number when telephony is available without requiring telephony -->
<uses-feature android:name="android.hardware.telephony" android:required="false"/>

该方法使用 Roman 根据设备支持的 API 级别描述的两种方法之一。它展示了如何利用用户设置的主要字段以及何时设置多个值。它使用 TelephonyManager 来检索设备的电话号码。

关于android - 如何获取Android设备上的用户个人资料,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13350844/

相关文章:

android - 某些操作不调用自定义 ContactsDirectoryProvider

android - 如何编写 ContactsContract 使其在 2.2 中运行并且不会在 1.5 中崩溃?

android - 使用 ContactsContract 有效地添加联系人

android - 添加联系人组会导致 HTC 和 Samsung 设备出现 NullPointerException

android - 如何将android中的日期选择器对话框设置为昨天的日期

java - 无法安装 Android APK

android - 非法状态异常 : couldn't move cursor to position

android - 如果用户离开 Activity ,则取消倒计时 (Kotlin)

android - 如何使用 Android 4+ 确认文件已通过蓝牙成功发送

android - Android 中的自定义联系人列表