这是我的java类。
public class MyPrefrences extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
在我的项目中,我使用了preferences.xml
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/steps_settings_title">
<ListPreference
android:key="sensitivity"
android:title="@string/setting"
android:summary="@string/setting_details"
android:entries="@array/preference"
android:entryValues="@array/preference_values"
android:dialogTitle="@string/setting_title"
android:defaultValue="30" />
<ListPreference
android:key="operation_level"
android:title="@string/operation_level_setting"
android:summary="@string/operation_level_setting_details"
android:entries="@array/operation_level_preference"
android:entryValues="@array/operation_level_preference_values"
android:dialogTitle="@string/operation_level_setting_title"
android:defaultValue="30" />
<ListPreference
android:key="units"
android:title="@string/units_setting"
android:summary="@string/units_setting_details"
android:entries="@array/units_preference"
android:entryValues="@array/units_preference_values"
android:dialogTitle="@string/units_setting_title"
android:defaultValue="imperial" />
<com.example.myapp.preferences.StepLengthPreference
android:key="length"
android:title="@string/length_setting"
android:summary="@string/length_setting_details"
android:dialogTitle="@string/length_setting_title"
android:defaultValue="20" />
<com.example.myapp.preferences.BodyWeightPreference
android:key="body_weight"
android:title="@string/weight_setting"
android:summary="@string/weight_setting_details"
android:dialogTitle="@string/weight_setting_title"
android:defaultValue="50" />
<ListPreference
android:key="exercise_type"
android:title="@string/type_setting"
android:summary="@string/type_setting_details"
android:entries="@array/type_preference"
android:entryValues="@array/type_preference_values"
android:dialogTitle="@string/type_setting_title"
android:defaultValue="running" />
<ListPreference
android:key="maintain"
android:title="@string/maintain_setting"
android:summary="@string/maintain_setting_details"
android:entries="@array/maintain_preference"
android:entryValues="@array/maintain_preference_values"
android:dialogTitle="@string/maintain_setting_title"
android:defaultValue="none" />
</PreferenceCategory>
</PreferenceScreen>
如何根据新的Google安全政策解决此问题。 您的应用程序具有不安全的实现,其中PreferenceActivity类可能容易受到片段注入的影响。 为Manifest中受影响的PreferenceActivity设置exported = false isValidFragment的实现不正确 他们怎么可能修好?
答案 0 :(得分:0)
这段代码非常适合我:
public class MyPrefrence extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new MyPreferenceFragment())
.commit();
}
public static class MyPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
}