How to open up phones settings page through prefer

2019-08-29 07:45发布

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条回答
Emotional °昔
2楼-- · 2019-08-29 08:03

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 
    }

}
查看更多
登录 后发表回答