Android - Creating Intents: Settings
- Dan Thompson
- Jan 30, 2018
- 1 min read
Hello all,
I really enjoyed the Android Basics by Google and Udacity lesson Practice with Intents so I am taking some time to fully explore each of the intents in the Android Common Intents documentation. The one I have most recently looked at is Settings.
First I just created a simple button to activate the intent which looks like this:

And the code in activity_main.xml looks like this:
<Button
android:id="@+id/settings"
android:layout_width="@dimen/button_width"
android:layout_height="@dimen/button_height"
android:layout_gravity="center"
android:layout_margin="@dimen/margin"
android:onClick="newSetting"
android:text="settings"/>
Then I created an activity in MainActivity.java to call the intent when the button is clicked. The following code gets you to the main settings screen.
public void newSetting(View view) {
Intent intent = new Intent(Settings.ACTION_SETTINGS);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
To get to different parts of the settings options you only need to change the following line of code Intent intent = new Intent(Settings.ACTION_SETTINGS);. For example
public void newSetting(View view) {
Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
Allows you to access to the wireless settings. And this following line of code:
public void newSetting(View view) {
Intent intent = new Intent(Settings.ACTION_AIRPLANE_MODE_SETTINGS);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
Allows you to toggle Airplane mode. A partial list of the other settings commands can be found in Android Common Intents documentation. There is also a link on this page to More information about settings and settings commands.
I welcome any comments or questions about this, especially corrections of anything I can improve. For example, are there any settings options you have tried and found to be particularly interesting or useful?
Comments