How to open up phones settings page through preferences?

99封情书 提交于 2019-12-11 16:26:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!