问题
I am making a settings page for an app and one of the features I want is for the user to change the permissions through the settings page by redirecting to the users phones settings.
I am trying to figured out how to do that programmatically. I am wondering if it can be done like the same way as android.intent.action.VIEW
through the preference like I show in the example or is there a different procedure I have to follow.
<Preference android:title="Example">
<intent android:action="android.intent.action.VIEW"
android:data="https://example.com/" />
</Preference>
回答1:
You can use onSharedPreferenceChanged Listener for this purpose !
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
// get the preference that has been changed
Preference selectedPreference= findPreference(key);
Object changedPreference = selectedPreference;
// Log.d("CHECK",selectedPreference.getTitle().toString());
// and if it's an instance of EditTextPreference class, update its summary
if (selectedPreference instanceof EditTextPreference) {
//Do your stuff
}
}
来源:https://stackoverflow.com/questions/49739998/how-to-open-up-phones-settings-page-through-preferences