Android java open settings

How to open Android Settings programmatically with Java

Carlos Delgado

In case your app needs that your user make some changes in the Settings menu i.e to set a default app to open a specific type of files etc, you may like to make this task easier for your user by starting the Settings menu of Android dinamically from your app.

Show system settings

To display the Settings page programmatically, you can use the startActivityForResult method with an Intent object and a constant of the Settings, the following example should open the general settings menu of Android:

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

The usage of the ACTION_SETTINGS constant with startActivityForResult will show system settings. The Settings provider contains global system-level device preferences.

Access specific settings areas

The following list contains all the constants that provide access to different areas of the settings menu:

Note: not all the constants are available on every Android version. In case you need more information visit the official documentation here.

Constants of android.provider.Settings

Activity Action: Show settings for accessibility modules.

Activity Action: Show add account screen for creating a new account.

Activity Action: Show settings to allow entering/exiting airplane mode.

Activity Action: Show settings to allow configuration of APNs.

Activity Action: Show screen of details about a particular application.

Activity Action: Show settings to allow configuration of application development-related settings.

Activity Action: Show settings to allow configuration of application-related settings.

Activity Action: Show battery saver settings.

Activity Action: Show settings to allow configuration of Bluetooth.

Activity Action: Show settings for video captioning.

Activity Action: Show settings to allow configuration of cast endpoints.

Activity Action: Show settings for selection of 2G/3G.

Activity Action: Show settings to allow configuration of date and time.

Activity Action: Show general device information settings (serial number, software version, phone number, etc.).

Activity Action: Show settings to allow configuration of display.

Activity Action: Show Daydream settings.

Activity Action: Show settings to configure the hardware keyboard.

Activity Action: Show Home selection settings.

Activity Action: Show screen for controlling background data restrictions for a particular application.

Activity Action: Show screen for controlling which apps can ignore battery optimizations.

Activity Action: Show settings to configure input methods, in particular allowing the user to enable input methods.

Activity Action: Show settings to enable/disable input method subtypes.

Activity Action: Show settings for internal storage.

Activity Action: Show settings to allow configuration of locale.

Activity Action: Show settings to allow configuration of current location sources.

Activity Action: Show settings to manage all applications.

Activity Action: Show settings to manage installed applications.

Activity Action: Show Default apps settings.

Activity Action: Show screen for controlling which apps can draw on top of other apps.

Activity Action: Show screen for controlling which apps are allowed to write/modify system settings.

Activity Action: Show settings for memory card storage.

Activity Action: Show settings for selecting the network operator.

Activity Action: Show NFC Sharing settings.

Activity Action: Show NFC Tap & Pay settings

This shows UI that allows the user to configure Tap&Pay settings.

Activity Action: Show NFC settings.

Activity Action: Show Notification listener settings.

Activity Action: Show Do Not Disturb access settings.

Activity Action: Show the top level print settings.

Activity Action: Show settings to allow configuration of privacy options.

Activity Action: Show settings to allow configuration of quick launch shortcuts.

Activity Action: Ask the user to allow an app to ignore battery optimizations (that is, put them on the whitelist of apps shown by ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS ).

Activity Action: Show settings for global search.

Activity Action: Show settings to allow configuration of security and location privacy.

Activity Action: Show system settings.

Activity Action: Show the regulatory information screen for the device.

Activity Action: Show settings to allow configuration of sound and volume.

Activity Action: Show settings to allow configuration of sync settings.

Activity Action: Show settings to control access to usage information.

Activity Action: Show settings to manage the user input dictionary.

Activity Action: Modify Airplane mode settings using a voice command.

Activity Action: Modify Battery Saver mode setting using a voice command.

Activity Action: Modify do not disturb mode settings.

Activity Action: Show settings to configure input methods, in particular allowing the user to enable input methods.

Activity Action: Show settings to allow configuration of VPN.

Activity Action: Show VR listener settings.

Activity Action: Allows user to select current webview implementation.

Activity Action: Show settings to allow configuration of a static IP address for Wi-Fi.

Activity Action: Show settings to allow configuration of Wi-Fi.

Activity Action: Show settings to allow configuration of wireless controls such as Wi-Fi, Bluetooth and Mobile networks.

Activity Extra: Limit available options in launched activity based on the given account types.

Activity Extra: Enable or disable Airplane Mode.

Activity Extra: Limit available options in launched activity based on the given authority.

Activity Extra: Enable or disable Battery saver mode.

Activity Extra: Enable or disable Do Not Disturb mode.

Activity Extra: How many minutes to enable do not disturb mode for.

Activity Category: Show application settings related to usage access.

Metadata key: Reason for needing usage access.

For example, you can open directly the Language Settings of the device (to change language) executing:

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

With the introduction of new Android APIs, there will be more settings available areas with different constants, read the official documentation of android provider settings here.

Add the permissions if required

For some special areas of the Android Settings, you will need permissions. For example, to open the bluetooth settings you’ll need to add the following bluetooth permissions in your app manifest:

And then you’ll be able to open the bluetooth settings:

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

Otherwise you’ll get the following exception:

java.lang.SecurityException: Permission Denial: starting Intent <> requires android.permission.BLUETOOTH_ADMIN

Источник

Android open Settings Panel programmatically

Open Settings Panel

In this article, we will learn to open the settings panel programmatically in Android. The Settings.Panel is introduced in Android Q (API 29).

2. Open Settings panel programmatically in Android

Consider we have an app that won’t work without Internet connectivity. So whenever the user opens the application without an internet connection, we will redirect them to the device settings app to turn ON Mobile Data or WiFi. However, the user has to leave our app to navigate to the settings app.

To address the above problem of users needing to leave the current app and open settings application, therefore Android introduces the Settings panel, a floating UI with a fixed subset of settings.

Right now, the Settings panel supports the following settings options:

Let’s learn to show each of these options from your app.

2.1. Internet connectivity Settings panel

You can use the action ACTION_INTERNET_CONNECTIVITY to show the internet connectivity settings panel for users.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)

2.2. Android NFC Settings panel

To launch the NFC settings panel, use the action ACTION_NFC:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)

2.3. Android WiFi settings panel

You can use the WiFi settings panel to change the Wifi or toggle. To show the dialog, invoke intent with the action ACTION_WIFI.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)

2.4. Android Volume Settings panel

To show the Volume settings panel to adjust the volume, use the action ACTION_VOLUME.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)

2.5. Receive callback using ActivityResultLauncher

Since startActivityForResult is deprecated, we are using the ActivityResultLauncher.launch to launch the intent. The registerForActivityResult reduces complexity such as managing request codes with the startActivityForResult .

First, we had to invoke the new method registerForActivityResult to create the ActivityResultLauncher . Once the instance ActivityResultLauncher is ready, we can then use it to launch the Intents.

For example, the following registerForActivityResult method handles callback from the Settings panel.

var resultLauncher = registerForActivityResult( ActivityResultContracts.StartActivityForResult()) < result ->if (result.resultCode == Activity.RESULT_OK) < >>

If the user presses the “DONE” button in the settings panel dialog or device back button, then the RESULT_CANCELLED result code is returned back to the Activity or Fragment’s ActivityResultLauncher callback method. Inside your callback method, you can write code to check the Wi-Fi \ NFC \ internet connectivity.

Settings Panel Android - Volume

Settings Panel Android - NFC

Internet connectivity settings

Settings panel Android - Wifi

3. Conclusion

To sum up, the Settings panel ease things for users and enhance user experience. To learn more about Android, refer to our articles.

7 thoughts on “Android open Settings Panel programmatically”

  1. Pingback: Alternative to startActivityForResult deprecated — TedBlob
  2. Pingback: OnRequestPermissionsResult deprecated Android Java — TedBlob
  3. Pingback: startActivityForResult deprecated google sign in — TedBlob
  4. Pingback: ActivityResultContracts.StartIntentSenderForResult — TedBlob
  5. Pingback: startActivityForResult deprecated camera — TedBlob
  6. Pingback: Android Open Settings Intent? Top Answer Update — Brandiscrafts.com
  7. Pingback: Android open settings programmatically – Answers Library

Источник

Читайте также:  Html тіліні негізгі ымдары
Оцените статью