How to open Settings panel in Android Q programmatically?
Asked Answered
B

1

7

As per Android Q new features, there is a inline settings panel showing key connectivity settings that lets the user modify different connectivity settings such as airplane mode, wifi, volume, NFC and internet connectivity.

How can I open that settings panel programmatically from my app? like in screenshot below.

enter image description here

Bailey answered 25/7, 2019 at 13:53 Comment(0)
B
21

This is very simple and easy to implement using Settings panel API available in Android Q.

Simple we need to trigger intent with one of the new Settings.Panel actions.

To open Internet Connectivity Panel:

enter image description here

Java:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
    Intent panelIntent = new Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY)
    startActivityForResult(panelIntent, 545)
}

Kotlin:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
    val panelIntent = Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY)
    startActivityForResult(panelIntent, 545)
}


To open Volume control panel:

enter image description here

Java:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
    Intent panelIntent = new Intent(Settings.Panel.ACTION_VOLUME)
    startActivityForResult(panelIntent, 545)
}

Kotlin:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
    val panelIntent = Intent(Settings.Panel.ACTION_VOLUME)
    startActivityForResult(panelIntent, 545)
}


To open WIFI panel:

enter image description here

Java:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
    Intent panelIntent = new Intent(Settings.Panel.ACTION_WIFI)
    startActivityForResult(panelIntent, 545)
}

Kotlin:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
    val panelIntent = Intent(Settings.Panel.ACTION_WIFI)
    startActivityForResult(panelIntent, 545)
}


To open NFC panel:

enter image description here

Java:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
    Intent panelIntent = new Intent(Settings.Panel.ACTION_NFC)
    startActivityForResult(panelIntent, 545)
}

Kotlin:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
    val panelIntent = Intent(Settings.Panel.ACTION_NFC)
    startActivityForResult(panelIntent, 545)
}

Here you can check more about settings panel from Android official doc:

1) https://developer.android.com/preview/features#settings-panels

2) https://developer.android.com/reference/android/provider/Settings.Panel

Bailey answered 25/7, 2019 at 13:53 Comment(5)
What is 545 here in the call to startActivityForResult?Pickar
@Pickar It is just request code for starting activity for result so that we the started activity returns a result in onActivityResult, you can check for which request this result is returned.Bailey
@BirjuVachhani It is also mentioned in the docs "We are planning to introduce an AndroidX wrapper for this functionality. When called on devices running Android 9 (API level 28) or lower, the wrapper will open the most-appropriate page in the Settings app." Is the AndroidX wrapper introduced yet?Moratorium
@MehulKanzariya Apparently, the wrapper idea has been canceled: reddit.com/r/androiddev/comments/f574wo/…Spectrogram
Will it work with android services?Lest

© 2022 - 2024 — McMap. All rights reserved.