Use Intent to open Android preference for editing [duplicate]
Possible Duplicate:
How to open or simulate a click on a android Preference, which was created with XML, from code programatically?
Is it possible to use an Intent to open a Preference in a PreferenceActivity? For example, I'm using an OnPreferenceChangeListener
to validate settings in an application, and rather than simply displaying an error message, I'd like to send the user back to the editing screen when an invalid value is entered.
Can an Intent open the editing screen? If not, is there another solution?
EDIT
Just to clarify, I'm not trying to access the Android device settings. I'm using a PreferenceActivity
to display a custom set of pref开发者_JAVA百科erences and want to create an Intent that allows the user to modify a specific preference. From the user's perspective, they would:
- Click on the preference
- Enter a value
- If the value is invalid, a message is displayed
- The user clicks "Ok"
- The app returns to the point where the user can enter a value (returns to step 2)
- If the value is valid, it is saved
When the user clicks ok, the app would immediately return to the point where a value can be entered, and does not require the user to click on the preference again.
I'm assuming you are referring to the Android Settings. You can create a new Intent, passing in "android.settings.SETTINGS"
:
startActivity(new Intent("android.settings.SETTINGS"));
Edit:
Now that I understand that you are using a PreferenceActivity, you should be able to override the onNewIntent(...) method to handle custom Intents (you can unpack the intent to see what the target preference is). From here, you can programmatically open the correct preference.
精彩评论