Reputation: 6620
How can I open settings programmatically?
Upvotes: 162
Views: 230698
Reputation: 635
Use this intent to open security and location screen in settings app of android device
startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS));
Upvotes: 3
Reputation: 2771
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)
Upvotes: 15
Reputation: 1739
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))
}
Upvotes: 4
Reputation: 1722
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.
Upvotes: 63
Reputation: 2049
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();
Upvotes: 1
Reputation: 6246
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.
Upvotes: 44
Reputation: 1686
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);
Upvotes: 1
Reputation: 243
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.
Upvotes: 22
Reputation: 4531
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);
}
}
Upvotes: 7
Reputation: 126455
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.
Upvotes: 7
Reputation: 4104
You can open with
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
You can return by pressing back button on device.
Upvotes: 233