I want to be able to automatically enter information into the create account form and suggest possibilities based on information the user has already entered into the device, like their name, email address, phone number. I need an approach that is compatible with back to API level 8.
I found Roman Nurik's answer to a pretty similar answer, and mine is thus based on his answer. Here's the gist of my answer. You will need to add permissions and features to the AndroidManifest.xml
to get to the user's 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"/>
The approach uses one of the two methods Roman describes based on the API level supported on the device. It shows how one can utilize the primary fields set by the user and when multiple values are set. And it uses the TelephonyManager
to retrieve the device's phone number.