urbanairship-core/src/main/java/com/urbanairship/iam/AudienceChecks.java
private static boolean isLocaleConditionMet(@NonNull Context context, @NonNull Audience audience) {
        if (audience.getLanguageTags().isEmpty()) {
            return true;
        }

        LocaleListCompat userLocales = ConfigurationCompat.getLocales(context.getResources().getConfiguration());

        // Find best locale
        Locale locale = userLocales.getFirstMatch(audience.getLanguageTags().toArray(new String[] {}));
        if (locale == null) {
            return false;
        }

        // getFirstMatch will return the default language if none of the specified locales are found,
        // so we still have to verify the locale exists in the audience conditions

        String tags = UAStringUtil.join(audience.getLanguageTags(), ",");
        LocaleListCompat audienceLocales = LocaleListCompat.forLanguageTags(tags);
        for (int i = 0; i < audienceLocales.size(); i++) {
            Locale audienceLocale = audienceLocales.get(i);

            if (!locale.getLanguage().equals(audienceLocale.getLanguage())) {
                continue;
            }

            if (!UAStringUtil.isEmpty(audienceLocale.getCountry()) && !audienceLocale.getCountry().equals(locale.getCountry())) {
                continue;
            }

            return true;
        }

        return false;
    }
/**
     * Helper method to check the locales.
     *
     * @param context The application context.
     * @param audience The audience.
     * @return {@code true} if the locale conditions are met or are not defined, otherwise {@code false}.
     */
Helper method to check the locales.
@param context The application context.
@param audience The audience.
@return  true if the locale conditions are met or are not defined, otherwise  false.
Helper method to check the locales . @param context The application context . @param audience The audience . @return true if the locale conditions are met or are not defined otherwise false .
private static boolean isLocaleConditionMet(@NonNull Context context, @NonNull Audience audience) {
        if (audience.getLanguageTags().isEmpty()) {
            return true;
        }
        LocaleListCompat userLocales = ConfigurationCompat.getLocales(context.getResources().getConfiguration());
        Locale locale = userLocales.getFirstMatch(audience.getLanguageTags().toArray(new String[] {}));
        if (locale == null) {
            return false;
        }
        String tags = UAStringUtil.join(audience.getLanguageTags(), ",");
        LocaleListCompat audienceLocales = LocaleListCompat.forLanguageTags(tags);
        for (int i = 0; i < audienceLocales.size(); i++) {
            Locale audienceLocale = audienceLocales.get(i);
            if (!locale.getLanguage().equals(audienceLocale.getLanguage())) {
                continue;
            }
            if (!UAStringUtil.isEmpty(audienceLocale.getCountry()) && !audienceLocale.getCountry().equals(locale.getCountry())) {
                continue;
            }
            return true;
        }
        return false;
    }
private static boolean isLocaleConditionMet ( @ NonNull Context context , @ NonNull Audience audience ) { if ( audience . getLanguageTags ( ) . isEmpty ( ) ) { return true ; } LocaleListCompat userLocales = ConfigurationCompat . getLocales ( context . getResources ( ) . getConfiguration ( ) ) ; Locale locale = userLocales . getFirstMatch ( audience . getLanguageTags ( ) . toArray ( new String [ ] { } ) ) ; if ( locale == null ) { return false ; } String tags = UAStringUtil . join ( audience . getLanguageTags ( ) , "," ) ; LocaleListCompat audienceLocales = LocaleListCompat . forLanguageTags ( tags ) ; for ( int i = 0 ; i < audienceLocales . size ( ) ; i ++ ) { Locale audienceLocale = audienceLocales . get ( i ) ; if ( ! locale . getLanguage ( ) . equals ( audienceLocale . getLanguage ( ) ) ) { continue ; } if ( ! UAStringUtil . isEmpty ( audienceLocale . getCountry ( ) ) && ! audienceLocale . getCountry ( ) . equals ( locale . getCountry ( ) ) ) { continue ; } return true ; } return false ; }
Helper method to check the locales.
Helper method to check the locales .
// Find best locale // getFirstMatch will return the default language if none of the specified locales are found, // so we still have to verify the locale exists in the audience conditions