回答

5

我发现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"/> 

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

+0

感谢您的罗马,抱歉误拼您的名字。 –

相关问题