Open Specific Settings Using Android Application

In android development the phase comes where the app needs the specific settings to be modified manually by user. So at that time developer directs the user to open specific settings and modify them. So in this article it has been discussed on how to open specific settings and make the user change them easily.

Step 1: Create new Empty Activity android project

Step 2 : You may change the color combination of the application

  • You may change the color combination of the base theme of the application. To change it open app -> src -> main -> res -> values -> colors.xml.
  • Invoke the following code in colors.xml.

XML

filter_none

edit
close

play_arrow

link
brightness_4
code

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#0f9d58</color>
    <color name="colorPrimaryDark">#006d2d</color>
    <color name="colorAccent">#55cf86</color>
</resources>

chevron_right


  • You may refer the following image to get the colors.xml file.



Step 3: Working with activity_main.xml

  • Here, Buttons are used to open each of the specific settings. There are many different settings in android out of all of them seven are most commonly used. So seven buttons are added to the activity layout.
  • Invoke the following code inside activity_main.xml :

XML

filter_none

edit
close

play_arrow

link
brightness_4
code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity"
    tools:ignore="HardcodedText">
  
    <!--Make sure to give appropriate IDs to all buttons so that can be easily handled-->
  
    <!--Button to open wireless settings-->
    <Button
        android:id="@+id/wireless_settings"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:backgroundTint="@color/colorPrimary"
        android:text="Open Wireless Settings"
        android:textColor="@android:color/white" />
  
    <!--Button to open wifi settings-->
    <Button
        android:id="@+id/wifi_settings"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:backgroundTint="@color/colorPrimary"
        android:text="Open Wi-Fi Settings"
        android:textColor="@android:color/white" />
  
    <!--Button to open bluetooth settings-->
    <Button
        android:id="@+id/bluetooth_settings"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:backgroundTint="@color/colorPrimary"
        android:text="Open Bluetooth Settings"
        android:textColor="@android:color/white" />
  
    <!--Button to open date settings-->
    <Button
        android:id="@+id/date_settings"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:backgroundTint="@color/colorPrimary"
        android:text="Open Date Settings"
        android:textColor="@android:color/white" />
  
    <!--Button to open input method settings-->
    <Button
        android:id="@+id/input_method_settings"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:backgroundTint="@color/colorPrimary"
        android:text="Open Input Method Settings"
        android:textColor="@android:color/white" />
  
    <!--Button to open display settings-->
    <Button
        android:id="@+id/display_settings"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:backgroundTint="@color/colorPrimary"
        android:text="Open Display Settings"
        android:textColor="@android:color/white" />
  
    <!--Button to open Location settings-->
    <Button
        android:id="@+id/location_settings"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:backgroundTint="@color/colorPrimary"
        android:text="Open Location Settings"
        android:textColor="@android:color/white" />
  
</LinearLayout>

chevron_right


Following output UI is produced :

Step 4: Working with MainActivity.kt file

Java

filter_none

edit
close

play_arrow

link
brightness_4
code

package com.adityamshidlyali.openspecificsettings
  
    import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.provider.Settings.*import android.view.View import kotlinx.android.synthetic.main.activity_main.*
  
    class MainActivity : AppCompatActivity() {
  
    override fun onCreate(savedInstanceState: Bundle?)
    {
        super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)
  
            // Handle wireless settings button
            wireless_settings
            ?.setOnClickListener(View.OnClickListener{
                 val i = Intent(ACTION_WIRELESS_SETTINGS)
                     startActivity(i) })
  
             // Handle wifi settings button
             wifi_settings
            ?.setOnClickListener(View.OnClickListener{
                 val i = Intent(ACTION_WIFI_SETTINGS)
                     startActivity(i) })
  
             // Handle bluetooth settings button
             bluetooth_settings
            ?.setOnClickListener(View.OnClickListener{
                 val i = Intent(ACTION_BLUETOOTH_SETTINGS)
                     startActivity(i) })
  
             // Handle date settings button
             date_settings
            ?.setOnClickListener(View.OnClickListener{
                 val i = Intent(ACTION_DATE_SETTINGS)
                     startActivity(i) })
  
             // Handle input method settings button
             input_method_settings
            ?.setOnClickListener(View.OnClickListener{
                 val i
                 = Intent(ACTION_INPUT_METHOD_SETTINGS)
                     startActivity(i) })
  
             // Handle display settings button
             display_settings
            ?.setOnClickListener(View.OnClickListener{
                 val i = Intent(ACTION_DISPLAY_SETTINGS)
                     startActivity(i) })
  
             // Handle location settings button
             location_settings
            ?.setOnClickListener(View.OnClickListener{
                 val i
                 = Intent(ACTION_LOCATION_SOURCE_SETTINGS)
                     startActivity(i) })
    }
}

chevron_right


Note: Make sure to import the android.provider.Settings package to import all the settings class in project:

import android.provider.Settings.*

Output:

  • For more of the settings screens you may refer this official documentation.

Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.