156

How can I open settings programmatically?

Behnam
  • 6,510
  • 6
  • 35
  • 65

12 Answers12

227

You can open with

startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);

You can return by pressing back button on device.

kjurkovic
  • 4,044
  • 2
  • 23
  • 28
  • any way to get back when user pressed Clear Cache button ? – SweetWisher ツ Nov 28 '14 at 05:09
  • 1
    @SweetWisherヅ You just have to edit the source code. – Behnam Feb 14 '15 at 05:17
  • 2
    Now you can use Intent intent = new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS); startActivity(intent); There are whole bunch of constants for every main settings category that you can choose from. Just write Settings. and Android Studio will show you all categories in autocomplete. – Asim Gasimzade Feb 06 '18 at 11:39
  • 2
    Can I search a particular setting within Settings App and open that particular setting programmatically from my App? e.g. can I search OTG from my app in Settings of the phone? – Divya Gupta Jan 24 '20 at 10:40
  • It seems to me using StartActivity is enough, I get always get the result CANCELD when coming back to the App (which is normal when coming back with back button). Thus the app is not notified of changed settings this way. – this.myself Mar 17 '20 at 15:15
  • @kjurkovic can you please explain why there is need to startActivityForResult, You can simply open setting app using ===> startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS)); – The Black Horse Apr 24 '20 at 15:23
  • As this code opens settings in the same window, it can mess up the functionality of your app. Use the code from [this anwer](https://stackoverflow.com/a/62092663/12787264) to prevent that. – finnmglas May 29 '20 at 18:45
  • @TheBlackHorse because with startActivityForResult you can do some checks if you need to when you come back to app from settings in `onActivityResult` method. It works with startActivity as well. @finnmglas Android doesn't have windows. It has activities - since settings is a separate app, with it's own activities, makes what you say totally stupid – kjurkovic Jun 01 '20 at 15:37
60

I used the code from the most upvoted answer:

startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);

It opens the device settings in the same window, thus got the users of my android application (finnmglas/Launcher) for android stuck in there.

The answer for 2020 and beyond (in Kotlin):

startActivity(Intent(Settings.ACTION_SETTINGS))

It works in my app, should also be working in yours without any unwanted consequences.

Jéwôm'
  • 3,753
  • 5
  • 40
  • 73
finnmglas
  • 1,626
  • 4
  • 22
  • 37
44

This did it for me

Intent callGPSSettingIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(callGPSSettingIntent);

When they press back it goes back to my app.

TMH
  • 6,096
  • 7
  • 51
  • 88
22

You can try to call:

startActivityForResult(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS));

for other screen in setting screen, you can go to

https://developer.android.com/reference/android/provider/Settings.html

Hope help you in this case.

Iman Marashi
  • 5,593
  • 38
  • 51
13

In case anyone finds this question and you want to open up settings for your specific application:

    val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
    intent.data = Uri.parse("package:" + context.packageName)
    startActivity(intent)
tim.paetz
  • 2,635
  • 20
  • 23
9

Check out the Programmatically Displaying the Settings Page

    startActivity(context, new Intent(Settings.ACTION_SETTINGS), /*options:*/ null);

In general, you use the predefined constant Settings.ACTION__SETTINGS. The full list can be found here

Irwin Nawrocki
  • 337
  • 4
  • 7
GrIsHu
  • 29,068
  • 10
  • 64
  • 102
  • 1
    Is there a way to open the settings into the new option: "Control which applications can read your notifications" (added in API 18)? – Javi Mar 05 '14 at 17:04
7

To achieve this just use an Intent using the constant ACTION_SETTINGS, specifically defined to show the System Settings:

startActivity(new Intent(Settings.ACTION_SETTINGS));

startActivityForResult() is optional, only if you want to return some data when the settings activity is closed.

startActivityForResult(new Intent(Settings.ACTION_SETTINGS), 0);

here you can find a list of contants to show specific settings or details of an aplication.

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
6

You can make another class for doing this kind of activities.

public class Go {

   public void Setting(Context context)
    {
        Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }
}
Shohan Ahmed Sijan
  • 4,391
  • 1
  • 33
  • 39
3

Use this intent to open security and location screen in settings app of android device

    startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS));
Satender Kumar
  • 627
  • 4
  • 7
3

Following the new api described on: https://developer.android.com/training/permissions/requesting

private val goToSettingsRequest = registerForActivityResult(
    ActivityResultContracts.StartActivityForResult()
) { activityResult ->
    // TODO: DEAL WITH THE CALLBACK
}

private fun goToSettings() {
    goToSettingsRequest.launch(Intent(Settings.ACTION_SETTINGS))
}
Felipe R. Saruhashi
  • 1,709
  • 16
  • 22
1

Send User to Settings With located Package, example for WRITE_SETTINGS permission:

startActivityForResult(new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS).setData(Uri.parse("package:"+getPackageName()) ),0);
phnghue
  • 1,578
  • 2
  • 10
  • 9
1

open android location setting programmatically using alert dialog

AlertDialog.Builder alertDialog = new AlertDialog.Builder(YourActivity.this);
alertDialog.setTitle("Enable Location");
alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");
alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(intent);
      }
});
alertDialog.show();
Aftab Alam
  • 1,969
  • 17
  • 17