使用adb命令查看当前设备的国家码
adb root
adb shell getprop findstr country
根据adb获得可以判断国家码的属性
在代码中通过获得的属性进行判断
if(“US”.equalsIgnoreCase(SystemProperties.get("ro.product.countrycode",""))){
//符合的国家码进行的逻辑
}
遍历Switchpreference然后展示
getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY);
setPreferencesFromResource(R.xml.launcher_preferences, rootKey);
PreferenceScreen screen = getPreferenceScreen();
for (int i = screen.getPreferenceCount() - 1; i >= 0; i--) {
Preference preference = screen.getPreference(i);
if (!initPreference(preference)) {
screen.removePreference(preference);//关闭删除某一个控件
} else {
preference.setOnPreferenceChangeListener((preferences, newValue) -> {
mSharedPrefs.edit().putBoolean(preferences.getKey(), (Boolean) newValue).apply();
if(preferences.getKey().equals(RECENT_USED_PREFERENCE_KEY)){
onSwitchStateUpdateListener.onStateUpdate(0);
}else if(preferences.getKey().equals(ALL_APPS_ENTRY_PREFERENCE_KEY)){
onSwitchStateUpdateListener.onStateUpdate(1);
}else if(preferences.getKey().equals(KEY_ENABLE_MINUS_ONE)){
SharedPreferences sharedPreferences=mlauncher.getSharedPreferences("googlenagative",MODE_PRIVATE);
SharedPreferences.Editor editor=sharedPreferences.edit();
if((newValue+"").equals("true")){
editor.putBoolean("isopen",true);
}else{
editor.putBoolean("isopen",false);
}
editor.commit();
mlauncher.getWorkspace().requestLayout();
}else if(preferences.getKey().equals(ADD_ICON_PREFERENCE_KEY)){
}else if(preferences.getKey().equals(RECENT_INSTALL_PREFERENCE_KEY)){
}
return true;
});
}
}