我希望能够自动将信息输入到创建帐户表单中,并根据用户已输入到设备中的信息(例如姓名、电子邮件地址、电话号码)提出可能性建议。我需要一种与 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/