Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 更改语言三星S8+;_Java_Android_Android Studio_Sharedpreferences_Locale - Fatal编程技术网

Java 更改语言三星S8+;

Java 更改语言三星S8+;,java,android,android-studio,sharedpreferences,locale,Java,Android,Android Studio,Sharedpreferences,Locale,我在三星S8+(android 9.0)中面临着语言变化问题。 我已经将一个版本的.aab(“Android应用程序包格式”)文件扩展名上传到我的应用程序的google play商店。 现在我在play store上获得了这个应用程序,我可以轻松下载。 我已经在多个设备上安装了这个应用程序,并且工作得非常好 但当我在三星S8+设备上更改语言时,该设备无法工作。 在我们的应用程序中,我们使用英语和日语两种语言,但为什么不在三星S8+设备上工作呢?我不知道,另一个设备工作得很好 然后,我在三星S8+

我在三星S8+(android 9.0)中面临着语言变化问题。 我已经将一个版本的.aab(“Android应用程序包格式”)文件扩展名上传到我的应用程序的google play商店。 现在我在play store上获得了这个应用程序,我可以轻松下载。 我已经在多个设备上安装了这个应用程序,并且工作得非常好

但当我在三星S8+设备上更改语言时,该设备无法工作。 在我们的应用程序中,我们使用英语和日语两种语言,但为什么不在三星S8+设备上工作呢?我不知道,另一个设备工作得很好

然后,我在三星S8+上安装了release.apk,并开始工作。所以我想知道为什么.aab不起作用而.apk起作用。请给出你的答案

请检查使用的代码

这是更改语言的基本方法

public void updateLocale() {
    String locality = MyApplication.getInstance().getSharedPref().getLanguage();
    if (locality != null && !locality.isEmpty() && locality.equals(Locale.ENGLISH.toString())) {
        Configuration configuration = getResources().getConfiguration();
        if (Build.VERSION.SDK_INT >= 17) {
            configuration.setLocale(new Locale(Locale.ENGLISH.toString()));
        } else {
            configuration.locale = new Locale(Locale.ENGLISH.toString());
        }
        getResources().updateConfiguration(configuration, getResources().getDisplayMetrics());
        onConfigurationChanged(configuration);
    } else {
        Configuration configuration = getResources().getConfiguration();
        if (Build.VERSION.SDK_INT >= 17) {
            configuration.setLocale(new Locale(Locale.JAPANESE.toString()));
        } else {
            configuration.locale = new Locale(Locale.JAPANESE.toString());
        }
        getResources().updateConfiguration(configuration, getResources().getDisplayMetrics());
        onConfigurationChanged(configuration);
    }
}
关于更改语言屏幕

Switch svChangeLang;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mSharedPref = new SharedPreference(getApplicationContext());
    svChangeLang = (Switch) findViewById(R.id.sv_change_lang);

    String lanCode = mSharedPref.getLanguage();
    if (lanCode.equals(Locale.ENGLISH.toString()))
        svChangeLang.setChecked(true);
    else
        svChangeLang.setChecked(false);

    svChangeLang.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (!isChecked)
                svChangeLang.setChecked(false);
            else
                svChangeLang.setChecked(true);
            mSharedPref.setLanguage(isChecked ? Locale.ENGLISH.toString() : 
            Locale.JAPANESE.toString());

            updateLocale();
        }
     });
   }

默认情况下,这在应用程序捆绑包中是不可能的:Google Play仅在设备所选语言更改时下载资源

第二种解决方案:

android {
bundle {
    language {

        enableSplit = false
    }
}
}

但第二种解决方案增加了应用程序的安全性