Table of Contents

    In Android app development, the Autofill framework is supported in Android 8.0 (API level 26) and higher. Autofill service is working as a password manager that can fill out the data in the views. Autofill framework manages the communication between our app and an autofill service.

    Autofill framework allows users to easily autofill login id’s, personal info and credit card-like secure details also.

    Filling the form info is time-consuming. Also users can easily get frustrated with our apps so when we use this kind of framework it helps users to easily fill the info. Autofill framework improves the user experience by below two benefits:

    1. Less time spent in filling the form fields. Autofill framework saves users from re-typing information.
    2. Reduce the user input errors, especially on Mobile devices.

    Check below image where you can see a small pop-up of users saved information by autofill service.

     

    Optimize your app for autofill
    Optimize your app using an autofill framework without requiring special configuration.
    Set up the autofill environment
    This section describes how to implement autofill functionality for your app.
    Provide hints for autofill
    Autofill will simply work out of the box on Oreo. You have to add in your views just
    “android:autofillHints” attributes. Also you can set which views are important for fill up using the autofill services. For this you have to add the “android:importantForAutofill” attribute.

     

    The value of “android:importantForAutofill” attributes are following:

    auto : Android System decides the view is important for autofill or not.
    no : This view isn’t important for autofill.
    noExcludeDescendants : This view and its children aren't important for autofill.
    yes : This view is important for autofill.
    yesExcludeDescendants : This view is important for autofill, but its children aren't important for autofill.

    You can see below code for how to write autofill in your views.

    Also you can set the setAutofillHints() method programmatically.

    It’s a good practice to always provide an autofill hint with View.
    Below defined constants for autofill hint which are defined in android.view.View class.

    AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY : this hint indicating that view can be auto filled with a credit card expiration day.
    AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH :this hint indicating that view can be auto filled with a credit card expiration month.
    AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR : this hint indicating that view can be auto filled with a credit card expiration year.
    AUTOFILL_HINT_CREDIT_CARD_NUMBER : this hint indicating that view can be auto filled with a credit card number.
    AUTOFILL_HINT_CREDIT_SECUROTY_CODE : this hint indicating that view can be auto filled with a credit card security code.
    AUTOFILL_HINT_EMAIL_ADDRESS : this hint indicating that view can be auto filled with an email address.
    AUTOFILL_HINT_NAME : this hint indicating that view can be auto filled with a user’s real name.
    AUTOFILL_HINT_PASSOWRD : this hint indicating that view can be auto filled with a password.
    AUTOFILL_HINT_PHONE : this hint indicating that view can be auto filled with a phone number.
    AUTOFILL_HINT_POSTAL_ADDRESS : this hint indicating that view can be auto filled with a postal address.
    AUTOFILL_HINT_POSTAL_CODE : this hint indicating that view can be auto filled with a postal code.
    AUTOFILL_HINT_POSTAL_CODE : this hint indicating that view can be auto filled with a username.

    Also you can set the setImportantForAutoFill() method programmatically.

    Below defined constants for setImporantForAutofill() which are defined in android.view.View class.

    IMPORTANT_FOR_AUTOFILL_NO
    IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS
    IMPORTANT_FOR_AUTOFILL_YES
    IMPORTANT_FOR_AUTOFILL_AUTO

    Force An Autofill Request


    Sometimes, you may need to force an autofill request. like, TextView offers an autofill menu item when the user long-presses the view. Below code shows how to force an autofill request:
    fun setEventHandler(view: View) {
    val autoFillManager = requireContext().getSystemService(AutofillManager::class.java)
    autoFillManager?.requestAutofill(view)
    }
    Use the correct autofill type for data in picker controls
    Pickers are useful in some autofill scenarios by providing a UI that lets users change the value of a field that stores date or time data. Like, fill the credit card form, a date picker lets users enter or change the expiration date of their credit card. However, you must use another view, such as an EditText, to display the data when the picker isn't visible.

    EditText object natively expects autofill data of type AUTOFILL_TYPE_TEXT. Also like if you have a date field, implement the methods with logic that correctly handles values of type AUTOFILL_TYPE_DATE.

    Customize the autofill highlighted drawable
    When the view fills up with an autofill hint then the platform renders a Drawable over the view to indicate the view contents have been autofilled. By default, this drawable is a solid rectangle with a translucent color that is slightly darker than the app theme's color used to draw backgrounds.

    You have to add “android:autofilledHighlight” attribute in your activity theme for customize your autofill view background.

    You have to add the below code in your “res/values/styles.xml” file:

    An Android App development company should cater the 360 degree need of it client and ManekTech had always been stands with this believe. Few are the crucial services which needs be provided by all-round Android App Development Company. We create customized applications based on customer needs giving them powerful and scalable apps which is compatible to any android devices.

    About Author

    Manektech Team

    Jignen Pandya

    Vice President

    Responsible for creating a sales funnel, attracting top-of-the-funnel customers, and converting the target market.

    Subscribe to Our Newsletter!

    Join us to stay updated with our latest blog updates, marketing tips, service tips, trends, news and announcements!

    OUR OFFICES


    ManekTech's Global Presence

    USA

    4100 NW Loop 410, Suite 200, San Antonio, Texas, USA 78229

    UK

    7 Artisan Place Harrow, HA3 5DS

    India

    4th Floor, Timber Point, Prahaladnagar Road, Ahmedabad, Gujarat - 380015

    Germany

    Franz-Joseph-Strasse, 11,Munich, 80801, Germany

    South Africa

    The Business Centre No 1. Bridgeway Road, Bridgeway Precint, Century City, Cape Town, South Africa, 7446

    PREV
    NEXT