tobias
tobias

Reputation: 2362

How get the current language setting on Android

I want to change the view of my TimePicker to 24h, if a user of Germany is watching it.

So I want to have a code like this:

if(language-setting = Germany)
    tp.setIs24HourView(true);
else
    tp.setIs24HourView(false);

I think it should somehow work with "locale", but I can not figure it out.

Upvotes: 2

Views: 5565

Answers (4)

Italo Borssatto
Italo Borssatto

Reputation: 15709

Use:

context.getResources().getConfiguration().locale;

Upvotes: 1

ritesh4326
ritesh4326

Reputation: 627

Try this one

String language=Locale.getDefault().getLanguage();
    Log.d("lang", "langg"+language);
    if(language.equals("en")){
        Log.d("lang_english", "langg"+language);
        //send_msg_text.
    }
    if(language.equals("ar")){
        Log.d("lang_arabic", "langg"+language);
    }

Upvotes: 3

dmon
dmon

Reputation: 30168

You should be respecting the user setting, which you can get from DateFormat.is24HourFormat().

Upvotes: 2

PravinCG
PravinCG

Reputation: 7708

This should give you the current default

Locale.getDefault();

Based on this you can compare.

Upvotes: 0

Related Questions