How to get a user profile on an Android device

I want to be able to automatically enter information into an account creation form and suggest options based on information the user has already entered into the device, such as name, email address, phone number. I need an approach that is up to API level 8 compatible.

+2


source to share


1 answer


I found Roman Nurik answered a fairly similar answer, and mine thus builds on his answer. This is the gist of my answer . You will need to add permissions and features to in AndroidManifest.xml

order to navigate to the user profile:

<!-- 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"/>

      



This approach uses one of two methods that Roman describes based on the API level supported on the device. It shows how user-defined primary fields can be used and when multiple values ​​are specified. And to get the phone number of the device is used TelephonyManager

.

+5


source







All Articles