Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open Settings panel in Android Q programmatically?

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

like image 861
Birju Vachhani Avatar asked Jul 25 '19 13:07

Birju Vachhani


1 Answers

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

like image 76
Birju Vachhani Avatar answered Sep 18 '22 07:09

Birju Vachhani