Open specific Settings-page programmatically
Asked Answered
O

3

7

Is there any way to, in my app, to redirect a user to a specific settings 'page'? My app works as a lock screen app, so I want to be able to redirect the user directly to the "Lock Screen" section of the Android settings. (Preferably via a button or something similar)

Otoscope answered 11/8, 2016 at 7:1 Comment(2)
Possible duplicate of #19517917 See the android.provider.Settings Intents.Titania
Oh, didn't read the full thread - thanks mate, exactly what I need! Answer my question and i'll accept your answer if you want :)Otoscope
O
7

I managed to find the correct answer in an old Stackoverflow-post from a while back. The code snippet now looks like this:

Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
startActivity(intent);
Otoscope answered 11/8, 2016 at 9:40 Comment(1)
Can't accept my answer before 2 days time, but this is the correct one!Otoscope
S
10

ACTION_SECURITY_SETTINGS Intent:

 Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
 startActivity(intent);

For complete Settings Intents

Schoolfellow answered 11/8, 2016 at 7:13 Comment(0)
O
7

I managed to find the correct answer in an old Stackoverflow-post from a while back. The code snippet now looks like this:

Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
startActivity(intent);
Otoscope answered 11/8, 2016 at 9:40 Comment(1)
Can't accept my answer before 2 days time, but this is the correct one!Otoscope
T
1
val intent = Intent(Settings.ACTION_SECURITY_SETTINGS)
intent.flags =
    Intent.FLAG_ACTIVITY_NEW_TASK or
    Intent.FLAG_ACTIVITY_CLEAR_TOP

startActivity(intent)

Note the flags. These are optional, but necessary to remove the previous settings screen from the screen if it was previously open (this is needed if your application wants to open multiple settings screens).

Tacnaarica answered 11/4, 2021 at 11:39 Comment(1)
Java: intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP). Docs: This launch mode can also be used to good effect in conjunction with {@link #FLAG_ACTIVITY_NEW_TASK}: if used to start the root activity of a task, it will bring any currently running instance of that task to the foreground, and then clear it to its root state.Metalloid

© 2022 - 2025 — McMap. All rights reserved.