user8542613
user8542613

Reputation: 755

Android Firebase: Phone Authentication Custom Country Code

My code for Firebase authentication by phone is:

startActivityForResult(
    AuthUI.getInstance()
    .createSignInIntentBuilder()
    .setAvailableProviders(
        Collections.singletonList(newAuthUI.IdpConfig.Builder(AuthUI.PHONE_VERIFICATION_PROVIDER).build()))
    .build(), RC_SIGN_IN);

The result is Firebase auth. by phone

By default the country code is 1 (USA).

Do I need to set another country code by default (e.g. 244). How I can do this?

Upvotes: 3

Views: 4409

Answers (3)

Jude Osbert K
Jude Osbert K

Reputation: 1048

With the lastest(I am using 4.3.1) version of the libary you can directly set the default paramters while building the IdpConfig Object

AuthUI.IdpConfig.PhoneBuilder()
                            .setDefaultCountryIso("IN")
                            .build()

Example input: {'+52', 'us'}

PS: I am not sure when it was first added to the library

Upvotes: 2

user10844068
user10844068

Reputation: 1

public class CountryData {
    public static final String[] countryNames = {"Afghanistan", "Albania",
            "Algeria", "Andorra", "Angola", "Antartica", "Argentina", "Armenia",
            "Aruba", "Australia", "Austria", "Azerbaijan", "Bahrain", "Banglades", "Belarus", "Belgium", "Belize",
            "Benin", "Bhutan", "Bolivia", "Bosnia And Herzegovina", "Botswana", "Brazil", "Brunei Darussalam",
            "Bulgaria", "Brukina Faso", "Myanmar", "Brundi", "Combodia", "Cameroon", "Canada", "Cape Verde",
            "Central African Republic", "Chad", "Chile", "China", "Chrismas Island", "Cocos(Keeling) Islands",
            "Colombia", "Comoros", "Congo", "Cook Islands", "Costa Rica", "Crotia",
            "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibuti", "Timor-leste", "Ecuador", "Egypt", "El Salvador",
            "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Island (malvinas)", "Faroe Islands", "Fiji",
            "Finland", "France", "French Polynesia", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar",
            "Greece", "Greenland", "Guatemala", "Guinea", "Guinea-bissau", "Guyan", "Haiti",
            "Honduras", "Hong Kong", "Hungary", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy",
            "Ivory Coast", "Jamaica", "Japan", "Jordan", "KazaKhstan", "Kenya", "Kiribati", "Kuwait",
            "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg",
            "macao", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania",
            "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco",
            "Mozambique", "Nambia", "Nauru", "Nepal", "Netherland", "New Caledonia", "New Zealand", "Nicargua", "Niger", "Nigeria",
            "Niue", "Korea", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines",
            "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Romania", "Russian Federation", "Rwanda", "Saint Barthelemy", "Samoa",
            "San Marino", "Sao Tome And Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Island",
            "Somalia", "South Africa", "Korea", "Republic of", "Spain", "Sri Lanka", "Saint Helen", "Saint Pierre And Miquelon", "Sudan", "Suriname", "Swaziland",
            "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Togo", "Tokelau", "Tonga", "Tunisia", "Turkey", "Turkmenistan",
            "Tuvalu", "United Arab Emirates", "Uganda", "United Kingdom", "Ukraine", "Uruguay", "United States", "Uzbekistan", "Vanuatu", "Holy See (Vatican City State)",
            "Venezuela", "Viet Nam", "Wallis And Futuna", "Yemen", "Zambia", "Zimbabwe"};

    public static final String[] countryAreaCodes = {"93", "355", "213", "376", "244", "672", "54", "374", "297", "61", "43",
            "994", "973", "880", "375", "32", "501", "229", "975", "591", "387", "267", "55", "673", "359", "226", "95", "257", "855",
            "237", "55", "673", "359", "226", "95", "257", "855", "237", "1", "238", "236", "235", "56", "86", "61", "61",
            "57", "269", "242", "682", "506", "385", "53", "357", "420", "45", "253", "670", "593", "20", "503", "240", "291", "372", "251", "500",
            "298", "679", "358", "33", "689", "241", "220", "995", "49", "233", "350", "30", "299", "502", "224", "245", "592", "509", "504",
            "852", "36", "91", "62", "98", "964", "353", "44", "972", "39", "225", "1876", "81", "962", "7", "254", "686", "965", "996",
            "856", "371", "961", "266", "231", "218", "423", "370", "352", "853", "389", "261", "265", "60", "960", "223", "356", "692", "222",
            "230", "262", "52", "691", "373", "377", "976", "382", "212", "258", "264", "674", "977", "31", "687", "64", "505", "227", "234", "683", "850", "47",
            "968", "92", "680", "507", "675", "595", "51", "63", "870", "48", "351", "1", "974", "40", "7", "250", "590", "685", "378", "239", "966",
            "221", "381", "248", "232", "65", "421", "386", "677", "252", "27", "82", "34", "94", "290", "508", "249", "597", "268", "46", "41", "963", "886", "992",
            "255", "66", "228", "690", "676", "216", "90", "993", "688", "971", "256", "44", "380", "598", "1", "998", "678", "39", "58", "681", "967", "260", "263"};
}

Upvotes: -1

ap14
ap14

Reputation: 4731

 Bundle params = new Bundle();
 params.putString(EXTRA_DEFAULT_COUNTRY_CODE, "AO");

 IdpConfig phoneConfigWithDefaultNumber =
          new IdpConfig.Builder(AuthUI.PHONE_VERIFICATION_PROVIDER)
                  .setParams(params)
                  .build();

Refer to this link

Upvotes: 0

Related Questions