Saturday, June 01, 2013

Android Tip: Programmatically Displaying the Settings Page


Many a times, you need to programmatically redirect the user to the Settings page so that they can turn on certain features on the device before your application can work correctly For example, if your app uses Bluetooth and the Bluetooth radio is not turned on, you may want to programmatically display the Bluetooth settings page so that the user can turn it on.

Solution

To display the Settings page programmatically, you can use the startActivity() method together with an Intent object. The following shows some examples:

    //---display the main Settings page---
    startActivity(
        new Intent(Settings.ACTION_SETTINGS));
        
    //---display the Location access settings page---
    startActivity(new Intent(
        Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                
    //---display the Wireless & networks settings page---
    startActivity(new Intent(
        Settings.ACTION_AIRPLANE_MODE_SETTINGS));
        
    //---display the Bluetooth settings page---
    startActivity(new Intent(
        Settings.ACTION_BLUETOOTH_SETTINGS));
        
        In general, you use the predefined constant Settings.ACTION__SETTINGS. The full list can be found here: http://developer.android.com/reference/android/provider/Settings.html

No comments: