gpt4 book ai didi

安卓 : how to detect language has been changes on phone setting

转载 作者:太空狗 更新时间:2023-10-29 15:45:32 27 4
gpt4 key购买 nike

我如何检测我的手机语言是否已更改,例如 facebook 应用程序会通知我们:请稍等,我们正在准备您的语言

我在 onCreate() 中使用了 myString = Locale.getDefault().getDisplayLanguage();

在我的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
}
}
}

请给我建议,我还在学习中,会更加努力。谢谢。

最佳答案

您可以使用:ACTION_LOCALE_CHANGED

举个例子:

    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;
}

关于安卓 : how to detect language has been changes on phone setting,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34285383/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com