Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : how to detect language has been changes on phone setting

Tags:

android

locale

how could i detect if my phone language has been changed, like facebook application that will give us announce : please wait, we preparing your language

i used myString = Locale.getDefault().getDisplayLanguage();in my onCreate()

on my onCreate()

@Override
    public void onCreate(Bundle savedInstanceState) {
        String myString = Locale.getDefault().getDisplayLanguage();
        if(myString.equals("en"){
            ProgressDialog progressDialog = new ProgressDialog(getApplicationContext());
            progressDialog.setMessage("Please wait, we preparing your language");
            progressDialog.show();
            /*
            it will dismiss until the language has been prepared
             */
        }else{
            //do nothing
        }
    }
}

please give me suggestion, i still learning, will try harder. thank you.

like image 833
Sarudu Matra Avatar asked Dec 15 '15 09:12

Sarudu Matra


2 Answers

You can use: ACTION_LOCALE_CHANGED

Here an example:

    private BroadcastReceiver mLangReceiver = null;

    protected BroadcastReceiver setupLangReceiver(){

        if(mLangReceiver == null) {

            mLangReceiver = new BroadcastReceiver() {

                @Override
                public void onReceive(Context context, Intent intent) {
                    // do what you want
                }

            };

            IntentFilter filter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED);
            registerReceiver(mLangReceiver, filter);
        }

        return mLangReceiver;
    }
like image 90
Alessandro Verona Avatar answered Sep 30 '22 16:09

Alessandro Verona


What about to make a broadcast listener to: ACTION_LOCALE_CHANGED

Since "Locale represents a language/country/variant combination. Locales are used to alter the presentation of information such as numbers or dates to suit the conventions in the region they describe."

http://developer.android.com/reference/java/util/Locale.html

like image 37
narancs Avatar answered Sep 30 '22 18:09

narancs