android settings.system.putstring,Settings.System

Settings.System

public

static

final

class

Settings.System

System settings, containing miscellaneous system preferences. This

table holds simple name/value pairs. There are convenience

functions for accessing individual settings entries.

Summary

Constants

Control whether the accelerometer will be used to change screen

orientation.

This constant was deprecated

in API level 15.

Use

This constant was deprecated

in API level 17.

Use

This constant was deprecated

in API level 17.

Use

Persistent store for the system-wide default alarm alert.

This constant was deprecated

in API level 17.

Use

This constant was deprecated

in API level 15.

Use

This constant was deprecated

in API level 17.

Use

This constant was deprecated

in API level 17.

Use

This constant was deprecated

in API level 17.

Use

Determines whether remote devices may discover and/or connect to

this device.

This constant was deprecated

in API level 15.

Use

This constant was deprecated

in API level 15.

Use

Date format string

mm/dd/yyyy

dd/mm/yyyy

yyyy/mm/dd

This constant was deprecated

in API level 17.

Use

This constant was deprecated

in API level 15.

Use

This constant was deprecated

in API level 17.

This setting is no longer used.

CDMA only settings

DTMF tone type played by the dialer when dialing.

Whether the audible DTMF tones are played by the dialer when dialing.

What happens when the user presses the end call button if they're not

on a call.

Scaling factor for fonts, float.

Whether haptic feedback (Vibrate on tap) is enabled.

This constant was deprecated

in API level 15.

Use

This constant was deprecated

in API level 15.

Use

This constant was deprecated

in API level 15.

Use

This constant was deprecated

in API level 15.

Use

This constant was deprecated

in API level 17.

Use

Determines which streams are affected by ringer and zen mode changes.

Determines which streams are affected by mute.

This constant was deprecated

in API level 15.

Use

This constant was deprecated

in API level 21.

Use

Persistent store for the system-wide default notification sound.

This constant was deprecated

in API level 17.

Use

This constant was deprecated

in API level 17.

Use

This constant was deprecated

in API level 17.

Use

This constant was deprecated

in API level 17.

Use

Persistent store for the system-wide default ringtone URI.

The screen backlight brightness between 0 and 255.

Control whether to enable automatic brightness mode.

int

SCREEN_BRIGHTNESS_MODE value for automatic mode.

int

SCREEN_BRIGHTNESS_MODE value for manual mode.

The amount of time in milliseconds before the device goes to sleep or begins

to dream after a period of inactivity.

This constant was deprecated

in API level 15.

Use

Whether the setup wizard has been run before (on first boot), or if

it still needs to be run.

This constant was deprecated

in API level 17.

This functionality is no longer available as of

This constant was deprecated

in API level 15.

Each application that shows web suggestions should have its own

setting for this.

Whether the sounds effects (key clicks, lid open ...) are enabled.

Setting to enable Auto Caps in text editors.

Setting to enable Auto Punctuate in text editors.

Setting to enable Auto Replace (AutoText) in text editors.

Setting to showing password characters in text editors.

Display times as 12 or 24 hours

12

24

This constant was deprecated

in API level 17.

Use

Default screen rotation when no other policy applies.

This constant was deprecated

in API level 15.

Use

Whether vibrate is on for different events.

Whether the phone vibrates when it is ringing due to an incoming call.

This constant was deprecated

in API level 17.

Use

This constant was deprecated

in API level 17.

Use

This constant was deprecated

in API level 15.

Use

This constant was deprecated

in API level 17.

Use

int

This constant was deprecated

in API level 17.

Use

int

This constant was deprecated

in API level 17.

Use

This constant was deprecated

in API level 17.

Use

This constant was deprecated

in API level 17.

Use

This constant was deprecated

in API level 17.

Use

This constant was deprecated

in API level 17.

Use

This constant was deprecated

in API level 17.

Use

This constant was deprecated

in API level 17.

Use

This constant was deprecated

in API level 15.

Use

This constant was deprecated

in API level 15.

Use

This constant was deprecated

in API level 17.

Use

Fields

public

static

final

Uri

The content:// style URL for this table

public

static

final

Uri

A

public

static

final

Uri

A

public

static

final

Uri

A

Public constructors

Public methods

static

boolean

Checks if the specified app can modify system settings.

static

void

Convenience function to read all of the current

configuration-related settings into a

static

float

Convenience function for retrieving a single system settings value

as a floating point number.

static

float

Convenience function for retrieving a single system settings value

as a float.

static

int

Convenience function for retrieving a single system settings value

as an integer.

static

int

Convenience function for retrieving a single system settings value

as an integer.

static

long

Convenience function for retrieving a single system settings value

as a long.

static

long

Convenience function for retrieving a single system settings value

as a long.

static

boolean

This method was deprecated

in API level 17.

- Do not use

static

String

Look up a name in the database.

static

Uri

Construct the content URI for a particular name/value pair,

useful for monitoring changes with a ContentObserver.

static

boolean

Convenience function to write a batch of configuration-related

settings from a

static

boolean

Convenience function for updating a single settings value as a

floating point number.

static

boolean

Convenience function for updating a single settings value as an

integer.

static

boolean

Convenience function for updating a single settings value as a long

integer.

static

boolean

Store a name/value pair into the database.

static

void

This method was deprecated

in API level 17.

- Do not use

Inherited methods

Creates and returns a copy of this object.

boolean

Indicates whether some other object is "equal to" this one.

void

Called by the garbage collector on an object when garbage collection

determines that there are no more references to the object.

final

Class>

Returns the runtime class of this Object.

int

Returns a hash code value for the object.

final

void

Wakes up a single thread that is waiting on this object's

monitor.

final

void

Wakes up all threads that are waiting on this object's monitor.

Returns a string representation of the object.

final

void

wait(long timeout, int nanos)

Causes the current thread to wait until another thread invokes the

final

void

wait(long timeout)

Causes the current thread to wait until either another thread invokes the

final

void

Causes the current thread to wait until another thread invokes the

Constants

ACCELEROMETER_ROTATION

public static final String ACCELEROMETER_ROTATION

Control whether the accelerometer will be used to change screen

orientation. If 0, it will not be used unless explicitly requested

by the application; if 1, it will be used by default unless explicitly

disabled by the application.

Constant Value:

"accelerometer_rotation"

ADB_ENABLED

public static final String ADB_ENABLED

This constant was deprecated

in API level 15.

Use

Constant Value:

"adb_enabled"

AIRPLANE_MODE_ON

public static final String AIRPLANE_MODE_ON

This constant was deprecated

in API level 17.

Use

Constant Value:

"airplane_mode_on"

AIRPLANE_MODE_RADIOS

public static final String AIRPLANE_MODE_RADIOS

This constant was deprecated

in API level 17.

Use

Constant Value:

"airplane_mode_radios"

ALARM_ALERT

public static final String ALARM_ALERT

Persistent store for the system-wide default alarm alert.

Constant Value:

"alarm_alert"

ALWAYS_FINISH_ACTIVITIES

public static final String ALWAYS_FINISH_ACTIVITIES

This constant was deprecated

in API level 17.

Use

If 1, the activity manager will aggressively finish activities and

processes as soon as they are no longer needed. If 0, the normal

extended lifetime is used.

Constant Value:

"always_finish_activities"

ANDROID_ID

public static final String ANDROID_ID

This constant was deprecated

in API level 15.

Use

Constant Value:

"android_id"

ANIMATOR_DURATION_SCALE

public static final String ANIMATOR_DURATION_SCALE

This constant was deprecated

in API level 17.

Use

Scaling factor for Animator-based animations. This affects both the start delay and

duration of all such animations. Setting to 0 will cause animations to end immediately.

The default value is 1.

Constant Value:

"animator_duration_scale"

AUTO_TIME

public static final String AUTO_TIME

This constant was deprecated

in API level 17.

Use

Constant Value:

"auto_time"

AUTO_TIME_ZONE

public static final String AUTO_TIME_ZONE

This constant was deprecated

in API level 17.

Use

Constant Value:

"auto_time_zone"

BLUETOOTH_DISCOVERABILITY

public static final String BLUETOOTH_DISCOVERABILITY

Determines whether remote devices may discover and/or connect to

this device.

Type: INT

2 -- discoverable and connectable

1 -- connectable but not discoverable

0 -- neither connectable nor discoverable

Constant Value:

"bluetooth_discoverability"

BLUETOOTH_DISCOVERABILITY_TIMEOUT

public static final String BLUETOOTH_DISCOVERABILITY_TIMEOUT

Bluetooth discoverability timeout. If this value is nonzero, then

Bluetooth becomes discoverable for a certain number of seconds,

after which is becomes simply connectable. The value is in seconds.

Constant Value:

"bluetooth_discoverability_timeout"

BLUETOOTH_ON

public static final String BLUETOOTH_ON

This constant was deprecated

in API level 15.

Use

Constant Value:

"bluetooth_on"

DATA_ROAMING

public static final String DATA_ROAMING

This constant was deprecated

in API level 15.

Use

Constant Value:

"data_roaming"

DATE_FORMAT

public static final String DATE_FORMAT

Date format string

mm/dd/yyyy

dd/mm/yyyy

yyyy/mm/dd

Constant Value:

"date_format"

DEBUG_APP

public static final String DEBUG_APP

This constant was deprecated

in API level 17.

Use

Name of an application package to be debugged.

Constant Value:

"debug_app"

DEVICE_PROVISIONED

public static final String DEVICE_PROVISIONED

This constant was deprecated

in API level 15.

Use

Constant Value:

"device_provisioned"

DIM_SCREEN

public static final String DIM_SCREEN

This constant was deprecated

in API level 17.

This setting is no longer used.

Whether or not to dim the screen. 0=no 1=yes

Constant Value:

"dim_screen"

DTMF_TONE_TYPE_WHEN_DIALING

public static final String DTMF_TONE_TYPE_WHEN_DIALING

CDMA only settings

DTMF tone type played by the dialer when dialing.

0 = Normal

1 = Long

Constant Value:

"dtmf_tone_type"

DTMF_TONE_WHEN_DIALING

public static final String DTMF_TONE_WHEN_DIALING

Whether the audible DTMF tones are played by the dialer when dialing. The value is

boolean (1 or 0).

Constant Value:

"dtmf_tone"

END_BUTTON_BEHAVIOR

public static final String END_BUTTON_BEHAVIOR

What happens when the user presses the end call button if they're not

on a call.

Values:

0 - The end button does nothing.

1 - The end button goes to the home screen.

2 - The end button puts the device to sleep and locks the keyguard.

3 - The end button goes to the home screen. If the user is already on the

home screen, it puts the device to sleep.

Constant Value:

"end_button_behavior"

FONT_SCALE

public static final String FONT_SCALE

Scaling factor for fonts, float.

Constant Value:

"font_scale"

HAPTIC_FEEDBACK_ENABLED

public static final String HAPTIC_FEEDBACK_ENABLED

Whether haptic feedback (Vibrate on tap) is enabled. The value is

boolean (1 or 0).

Constant Value:

"haptic_feedback_enabled"

HTTP_PROXY

public static final String HTTP_PROXY

This constant was deprecated

in API level 15.

Use

Constant Value:

"http_proxy"

INSTALL_NON_MARKET_APPS

public static final String INSTALL_NON_MARKET_APPS

This constant was deprecated

in API level 15.

Use

Constant Value:

"install_non_market_apps"

LOCATION_PROVIDERS_ALLOWED

public static final String LOCATION_PROVIDERS_ALLOWED

This constant was deprecated

in API level 15.

Use

Constant Value:

"location_providers_allowed"

LOCK_PATTERN_ENABLED

public static final String LOCK_PATTERN_ENABLED

This constant was deprecated

in API level 15.

Use

Constant Value:

"lock_pattern_autolock"

LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED

public static final String LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED

This constant was deprecated

in API level 15.

Use

Constant Value:

"lock_pattern_tactile_feedback_enabled"

LOCK_PATTERN_VISIBLE

public static final String LOCK_PATTERN_VISIBLE

This constant was deprecated

in API level 15.

Use

Constant Value:

"lock_pattern_visible_pattern"

LOGGING_ID

public static final String LOGGING_ID

This constant was deprecated

in API level 15.

Use

Constant Value:

"logging_id"

MODE_RINGER

public static final String MODE_RINGER

This constant was deprecated

in API level 17.

Use

Constant Value:

"mode_ringer"

MODE_RINGER_STREAMS_AFFECTED

public static final String MODE_RINGER_STREAMS_AFFECTED

Determines which streams are affected by ringer and zen mode changes. The

stream type's bit should be set to 1 if it should be muted when going

into an inaudible ringer mode.

Constant Value:

"mode_ringer_streams_affected"

MUTE_STREAMS_AFFECTED

public static final String MUTE_STREAMS_AFFECTED

Determines which streams are affected by mute. The

stream type's bit should be set to 1 if it should be muted when a mute request

is received.

Constant Value:

"mute_streams_affected"

NETWORK_PREFERENCE

public static final String NETWORK_PREFERENCE

This constant was deprecated

in API level 15.

Use

Constant Value:

"network_preference"

NEXT_ALARM_FORMATTED

public static final String NEXT_ALARM_FORMATTED

This constant was deprecated

in API level 21.

Use

A formatted string of the next alarm that is set, or the empty string

if there is no alarm set.

Constant Value:

"next_alarm_formatted"

NOTIFICATION_SOUND

public static final String NOTIFICATION_SOUND

Persistent store for the system-wide default notification sound.

Constant Value:

"notification_sound"

PARENTAL_CONTROL_ENABLED

public static final String PARENTAL_CONTROL_ENABLED

This constant was deprecated

in API level 15.

Use

Constant Value:

"parental_control_enabled"

PARENTAL_CONTROL_LAST_UPDATE

public static final String PARENTAL_CONTROL_LAST_UPDATE

This constant was deprecated

in API level 15.

Use

Constant Value:

"parental_control_last_update"

PARENTAL_CONTROL_REDIRECT_URL

public static final String PARENTAL_CONTROL_REDIRECT_URL

This constant was deprecated

in API level 15.

Use

Constant Value:

"parental_control_redirect_url"

RADIO_BLUETOOTH

public static final String RADIO_BLUETOOTH

This constant was deprecated

in API level 17.

Use

Constant Value:

"bluetooth"

RADIO_CELL

public static final String RADIO_CELL

This constant was deprecated

in API level 17.

Use

Constant Value:

"cell"

RADIO_NFC

public static final String RADIO_NFC

This constant was deprecated

in API level 17.

Use

Constant Value:

"nfc"

RADIO_WIFI

public static final String RADIO_WIFI

This constant was deprecated

in API level 17.

Use

Constant Value:

"wifi"

RINGTONE

public static final String RINGTONE

Persistent store for the system-wide default ringtone URI.

If you need to play the default ringtone at any given time, it is recommended

you give

Constant Value:

"ringtone"

SCREEN_BRIGHTNESS

public static final String SCREEN_BRIGHTNESS

The screen backlight brightness between 0 and 255.

Constant Value:

"screen_brightness"

SCREEN_BRIGHTNESS_MODE

public static final String SCREEN_BRIGHTNESS_MODE

Control whether to enable automatic brightness mode.

Constant Value:

"screen_brightness_mode"

SCREEN_BRIGHTNESS_MODE_AUTOMATIC

public static final int SCREEN_BRIGHTNESS_MODE_AUTOMATIC

SCREEN_BRIGHTNESS_MODE value for automatic mode.

Constant Value:

1

(0x00000001)

SCREEN_BRIGHTNESS_MODE_MANUAL

public static final int SCREEN_BRIGHTNESS_MODE_MANUAL

SCREEN_BRIGHTNESS_MODE value for manual mode.

Constant Value:

0

(0x00000000)

SCREEN_OFF_TIMEOUT

public static final String SCREEN_OFF_TIMEOUT

The amount of time in milliseconds before the device goes to sleep or begins

to dream after a period of inactivity. This value is also known as the

user activity timeout period since the screen isn't necessarily turned off

when it expires.

Constant Value:

"screen_off_timeout"

SETTINGS_CLASSNAME

public static final String SETTINGS_CLASSNAME

This constant was deprecated

in API level 15.

Use

Constant Value:

"settings_classname"

SETUP_WIZARD_HAS_RUN

public static final String SETUP_WIZARD_HAS_RUN

Whether the setup wizard has been run before (on first boot), or if

it still needs to be run.

nonzero = it has been run in the past

0 = it has not been run in the past

Constant Value:

"setup_wizard_has_run"

SHOW_GTALK_SERVICE_STATUS

public static final String SHOW_GTALK_SERVICE_STATUS

Constant Value:

"SHOW_GTALK_SERVICE_STATUS"

SHOW_PROCESSES

public static final String SHOW_PROCESSES

This constant was deprecated

in API level 17.

This functionality is no longer available as of

Control whether the process CPU usage meter should be shown.

Constant Value:

"show_processes"

SHOW_WEB_SUGGESTIONS

public static final String SHOW_WEB_SUGGESTIONS

This constant was deprecated

in API level 15.

Each application that shows web suggestions should have its own

setting for this.

Constant Value:

"show_web_suggestions"

SOUND_EFFECTS_ENABLED

public static final String SOUND_EFFECTS_ENABLED

Whether the sounds effects (key clicks, lid open ...) are enabled. The value is

boolean (1 or 0).

Constant Value:

"sound_effects_enabled"

STAY_ON_WHILE_PLUGGED_IN

public static final String STAY_ON_WHILE_PLUGGED_IN

This constant was deprecated

in API level 17.

Use

Constant Value:

"stay_on_while_plugged_in"

TEXT_AUTO_CAPS

public static final String TEXT_AUTO_CAPS

Setting to enable Auto Caps in text editors. 1 = On, 0 = Off

Constant Value:

"auto_caps"

TEXT_AUTO_PUNCTUATE

public static final String TEXT_AUTO_PUNCTUATE

Setting to enable Auto Punctuate in text editors. 1 = On, 0 = Off. This

feature converts two spaces to a "." and space.

Constant Value:

"auto_punctuate"

TEXT_AUTO_REPLACE

public static final String TEXT_AUTO_REPLACE

Setting to enable Auto Replace (AutoText) in text editors. 1 = On, 0 = Off

Constant Value:

"auto_replace"

TEXT_SHOW_PASSWORD

public static final String TEXT_SHOW_PASSWORD

Setting to showing password characters in text editors. 1 = On, 0 = Off

Constant Value:

"show_password"

TIME_12_24

public static final String TIME_12_24

Display times as 12 or 24 hours

12

24

Constant Value:

"time_12_24"

TRANSITION_ANIMATION_SCALE

public static final String TRANSITION_ANIMATION_SCALE

This constant was deprecated

in API level 17.

Use

Scaling factor for activity transition animations. Setting to 0 will disable window

animations.

Constant Value:

"transition_animation_scale"

USB_MASS_STORAGE_ENABLED

public static final String USB_MASS_STORAGE_ENABLED

This constant was deprecated

in API level 15.

Use

Constant Value:

"usb_mass_storage_enabled"

USER_ROTATION

public static final String USER_ROTATION

Default screen rotation when no other policy applies.

When

Constant Value:

"user_rotation"

USE_GOOGLE_MAIL

public static final String USE_GOOGLE_MAIL

This constant was deprecated

in API level 15.

Use

Constant Value:

"use_google_mail"

VIBRATE_ON

public static final String VIBRATE_ON

Whether vibrate is on for different events. This is used internally,

changing this value will not change the vibrate. See AudioManager.

Constant Value:

"vibrate_on"

VIBRATE_WHEN_RINGING

public static final String VIBRATE_WHEN_RINGING

Whether the phone vibrates when it is ringing due to an incoming call. This will

be used by Phone and Setting apps; it shouldn't affect other apps.

The value is boolean (1 or 0).

Note: this is not same as "vibrate on ring", which had been available until ICS.

It was about AudioManager's setting and thus affected all the applications which

relied on the setting, while this is purely about the vibration setting for incoming

calls.

Constant Value:

"vibrate_when_ringing"

WAIT_FOR_DEBUGGER

public static final String WAIT_FOR_DEBUGGER

This constant was deprecated

in API level 17.

Use

If 1, when launching DEBUG_APP it will wait for the debugger before

starting user code. If 0, it will run normally.

Constant Value:

"wait_for_debugger"

WALLPAPER_ACTIVITY

public static final String WALLPAPER_ACTIVITY

This constant was deprecated

in API level 17.

Use

Name of activity to use for wallpaper on the home screen.

Constant Value:

"wallpaper_activity"

WIFI_MAX_DHCP_RETRY_COUNT

public static final String WIFI_MAX_DHCP_RETRY_COUNT

This constant was deprecated

in API level 15.

Use

Constant Value:

"wifi_max_dhcp_retry_count"

WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS

public static final String WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS

Constant Value:

"wifi_mobile_data_transition_wakelock_timeout_ms"

WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON

public static final String WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON

This constant was deprecated

in API level 15.

Use

Constant Value:

"wifi_networks_available_notification_on"

WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY

public static final String WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY

This constant was deprecated

in API level 15.

Use

Constant Value:

"wifi_networks_available_repeat_delay"

WIFI_NUM_OPEN_NETWORKS_KEPT

public static final String WIFI_NUM_OPEN_NETWORKS_KEPT

This constant was deprecated

in API level 15.

Use

Constant Value:

"wifi_num_open_networks_kept"

WIFI_ON

public static final String WIFI_ON

This constant was deprecated

in API level 15.

Use

Constant Value:

"wifi_on"

WIFI_SLEEP_POLICY

public static final String WIFI_SLEEP_POLICY

This constant was deprecated

in API level 17.

Use

Constant Value:

"wifi_sleep_policy"

WIFI_SLEEP_POLICY_DEFAULT

public static final int WIFI_SLEEP_POLICY_DEFAULT

This constant was deprecated

in API level 17.

Use

Constant Value:

0

(0x00000000)

WIFI_SLEEP_POLICY_NEVER

public static final int WIFI_SLEEP_POLICY_NEVER

This constant was deprecated

in API level 17.

Use

Constant Value:

2

(0x00000002)

WIFI_SLEEP_POLICY_NEVER_WHILE_PLUGGED

public static final int WIFI_SLEEP_POLICY_NEVER_WHILE_PLUGGED

This constant was deprecated

in API level 17.

Use

Constant Value:

1

(0x00000001)

WIFI_STATIC_DNS1

public static final String WIFI_STATIC_DNS1

This constant was deprecated

in API level 17.

Use

If using static IP, the primary DNS's IP address.

Example: "192.168.1.1"

Constant Value:

"wifi_static_dns1"

WIFI_STATIC_DNS2

public static final String WIFI_STATIC_DNS2

This constant was deprecated

in API level 17.

Use

If using static IP, the secondary DNS's IP address.

Example: "192.168.1.2"

Constant Value:

"wifi_static_dns2"

WIFI_STATIC_GATEWAY

public static final String WIFI_STATIC_GATEWAY

This constant was deprecated

in API level 17.

Use

If using static IP, the gateway's IP address.

Example: "192.168.1.1"

Constant Value:

"wifi_static_gateway"

WIFI_STATIC_IP

public static final String WIFI_STATIC_IP

This constant was deprecated

in API level 17.

Use

The static IP address.

Example: "192.168.1.51"

Constant Value:

"wifi_static_ip"

WIFI_STATIC_NETMASK

public static final String WIFI_STATIC_NETMASK

This constant was deprecated

in API level 17.

Use

If using static IP, the net mask.

Example: "255.255.255.0"

Constant Value:

"wifi_static_netmask"

WIFI_USE_STATIC_IP

public static final String WIFI_USE_STATIC_IP

This constant was deprecated

in API level 17.

Use

Whether to use static IP and other static network attributes.

Set to 1 for true and 0 for false.

Constant Value:

"wifi_use_static_ip"

WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE

public static final String WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE

Constant Value:

"wifi_watchdog_acceptable_packet_loss_percentage"

WIFI_WATCHDOG_AP_COUNT

public static final String WIFI_WATCHDOG_AP_COUNT

This constant was deprecated

in API level 15.

Use

Constant Value:

"wifi_watchdog_ap_count"

WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS

public static final String WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS

This constant was deprecated

in API level 15.

Use

Constant Value:

"wifi_watchdog_background_check_delay_ms"

WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED

public static final String WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED

This constant was deprecated

in API level 15.

Use

Constant Value:

"wifi_watchdog_background_check_enabled"

WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS

public static final String WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS

This constant was deprecated

in API level 15.

Use

Constant Value:

"wifi_watchdog_background_check_timeout_ms"

WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT

public static final String WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT

This constant was deprecated

in API level 15.

Use

Constant Value:

"wifi_watchdog_initial_ignored_ping_count"

WIFI_WATCHDOG_MAX_AP_CHECKS

public static final String WIFI_WATCHDOG_MAX_AP_CHECKS

This constant was deprecated

in API level 15.

Use

Constant Value:

"wifi_watchdog_max_ap_checks"

WIFI_WATCHDOG_ON

public static final String WIFI_WATCHDOG_ON

This constant was deprecated

in API level 15.

Use

Constant Value:

"wifi_watchdog_on"

WIFI_WATCHDOG_PING_COUNT

public static final String WIFI_WATCHDOG_PING_COUNT

This constant was deprecated

in API level 15.

Use

Constant Value:

"wifi_watchdog_ping_count"

WIFI_WATCHDOG_PING_DELAY_MS

public static final String WIFI_WATCHDOG_PING_DELAY_MS

This constant was deprecated

in API level 15.

Use

Constant Value:

"wifi_watchdog_ping_delay_ms"

WIFI_WATCHDOG_PING_TIMEOUT_MS

public static final String WIFI_WATCHDOG_PING_TIMEOUT_MS

This constant was deprecated

in API level 15.

Use

Constant Value:

"wifi_watchdog_ping_timeout_ms"

WINDOW_ANIMATION_SCALE

public static final String WINDOW_ANIMATION_SCALE

This constant was deprecated

in API level 17.

Use

Scaling factor for normal window animations. Setting to 0 will disable window

animations.

Constant Value:

"window_animation_scale"

Fields

CONTENT_URI

public static final Uri CONTENT_URI

The content:// style URL for this table

DEFAULT_ALARM_ALERT_URI

public static final Uri DEFAULT_ALARM_ALERT_URI

A

DEFAULT_NOTIFICATION_URI

public static final Uri DEFAULT_NOTIFICATION_URI

A

DEFAULT_RINGTONE_URI

public static final Uri DEFAULT_RINGTONE_URI

A

If the current default ringtone is in the DRM provider and the caller

does not have permission, the exception will be a

FileNotFoundException.

Public constructors

System

public System ()

Public methods

canWrite

public static boolean canWrite (Context context)

Checks if the specified app can modify system settings. As of API

level 23, an app cannot modify system settings unless it declares the

and the user specifically grants

the app this capability. To prompt the user to grant this approval,

the app must send an intent with the action

Parameters

context

Context: App context.

Returns

boolean

true if the calling app can write to system settings, false otherwise

getConfiguration

public static void getConfiguration (ContentResolver cr,

Configuration outConfig)

Convenience function to read all of the current

configuration-related settings into a

Parameters

cr

ContentResolver: The ContentResolver to access.

outConfig

Configuration: Where to place the configuration settings.

getFloat

public static float getFloat (ContentResolver cr,

String name,

float def)

Convenience function for retrieving a single system settings value

as a floating point number. Note that internally setting values are

always stored as strings; this function converts the string to an

float for you. The default value will be returned if the setting

is not defined or not a valid float.

Parameters

cr

ContentResolver: The ContentResolver to access.

name

String: The name of the setting to retrieve.

def

float: Value to return if the setting is not defined.

Returns

float

The setting's current value, or 'def' if it is not defined

or not a valid float.

getFloat

public static float getFloat (ContentResolver cr,

String name)

Convenience function for retrieving a single system settings value

as a float. Note that internally setting values are always

stored as strings; this function converts the string to a float

for you.

This version does not take a default value. If the setting has not

been set, or the string value is not a number,

it throws

Parameters

cr

ContentResolver: The ContentResolver to access.

name

String: The name of the setting to retrieve.

Returns

float

The setting's current value.

Throws

Thrown if a setting by the given

name can't be found or the setting value is not a float.

getInt

public static int getInt (ContentResolver cr,

String name,

int def)

Convenience function for retrieving a single system settings value

as an integer. Note that internally setting values are always

stored as strings; this function converts the string to an integer

for you. The default value will be returned if the setting is

not defined or not an integer.

Parameters

cr

ContentResolver: The ContentResolver to access.

name

String: The name of the setting to retrieve.

def

int: Value to return if the setting is not defined.

Returns

int

The setting's current value, or 'def' if it is not defined

or not a valid integer.

getInt

public static int getInt (ContentResolver cr,

String name)

Convenience function for retrieving a single system settings value

as an integer. Note that internally setting values are always

stored as strings; this function converts the string to an integer

for you.

This version does not take a default value. If the setting has not

been set, or the string value is not a number,

it throws

Parameters

cr

ContentResolver: The ContentResolver to access.

name

String: The name of the setting to retrieve.

Returns

int

The setting's current value.

Throws

Thrown if a setting by the given

name can't be found or the setting value is not an integer.

getLong

public static long getLong (ContentResolver cr,

String name)

Convenience function for retrieving a single system settings value

as a long. Note that internally setting values are always

stored as strings; this function converts the string to a long

for you.

This version does not take a default value. If the setting has not

been set, or the string value is not a number,

it throws

Parameters

cr

ContentResolver: The ContentResolver to access.

name

String: The name of the setting to retrieve.

Returns

long

The setting's current value.

Throws

Thrown if a setting by the given

name can't be found or the setting value is not an integer.

getLong

public static long getLong (ContentResolver cr,

String name,

long def)

Convenience function for retrieving a single system settings value

as a long. Note that internally setting values are always

stored as strings; this function converts the string to a long

for you. The default value will be returned if the setting is

not defined or not a long.

Parameters

cr

ContentResolver: The ContentResolver to access.

name

String: The name of the setting to retrieve.

def

long: Value to return if the setting is not defined.

Returns

long

The setting's current value, or 'def' if it is not defined

or not a valid long.

getShowGTalkServiceStatus

public static boolean getShowGTalkServiceStatus (ContentResolver cr)

This method was deprecated

in API level 17.

- Do not use

Parameters

cr

ContentResolver

Returns

boolean

getString

public static String getString (ContentResolver resolver,

String name)

Look up a name in the database.

Parameters

resolver

ContentResolver: to access the database with

name

String: to look up in the table

Returns

the corresponding value, or null if not present

getUriFor

public static Uri getUriFor (String name)

Construct the content URI for a particular name/value pair,

useful for monitoring changes with a ContentObserver.

Parameters

name

String: to look up in the table

Returns

the corresponding content URI, or null if not present

putConfiguration

public static boolean putConfiguration (ContentResolver cr,

Configuration config)

Convenience function to write a batch of configuration-related

settings from a

Parameters

cr

ContentResolver: The ContentResolver to access.

config

Configuration: The settings to write.

Returns

boolean

true if the values were set, false on database errors

putFloat

public static boolean putFloat (ContentResolver cr,

String name,

float value)

Convenience function for updating a single settings value as a

floating point number. This will either create a new entry in the

table if the given name does not exist, or modify the value of the

existing row with that name. Note that internally setting values

are always stored as strings, so this function converts the given

value to a string before storing it.

Parameters

cr

ContentResolver: The ContentResolver to access.

name

String: The name of the setting to modify.

value

float: The new value for the setting.

Returns

boolean

true if the value was set, false on database errors

putInt

public static boolean putInt (ContentResolver cr,

String name,

int value)

Convenience function for updating a single settings value as an

integer. This will either create a new entry in the table if the

given name does not exist, or modify the value of the existing row

with that name. Note that internally setting values are always

stored as strings, so this function converts the given value to a

string before storing it.

Parameters

cr

ContentResolver: The ContentResolver to access.

name

String: The name of the setting to modify.

value

int: The new value for the setting.

Returns

boolean

true if the value was set, false on database errors

putLong

public static boolean putLong (ContentResolver cr,

String name,

long value)

Convenience function for updating a single settings value as a long

integer. This will either create a new entry in the table if the

given name does not exist, or modify the value of the existing row

with that name. Note that internally setting values are always

stored as strings, so this function converts the given value to a

string before storing it.

Parameters

cr

ContentResolver: The ContentResolver to access.

name

String: The name of the setting to modify.

value

long: The new value for the setting.

Returns

boolean

true if the value was set, false on database errors

putString

public static boolean putString (ContentResolver resolver,

String name,

String value)

Store a name/value pair into the database.

Parameters

resolver

ContentResolver: to access the database with

name

String: to store

value

String: to associate with the name

Returns

boolean

true if the value was set, false on database errors

setShowGTalkServiceStatus

public static void setShowGTalkServiceStatus (ContentResolver cr,

boolean flag)

This method was deprecated

in API level 17.

- Do not use

Parameters

cr

ContentResolver

flag

boolean

<think>嗯,用户问的问题是关于Android关机流程中,使用Settings.System.putInt写入数据后执行关机,有时候数据没保存的问题。首先,我需要回忆一下Settings.System.putInt的工作机制。用户之前已经了解过这个方法是同步的,所以理论上调用后数据应该已经写入数据库了。但现在出现数据未保存的情况,可能存在其他原因。 首先,我应该考虑Android系统的关机流程是怎样的。关机时系统会终止各个进程,可能包括系统服务,比如负责处理设置写入的ContentProvider或者SystemServer中的相关部分。如果关机流程在putInt调用之后很快开始,可能导致ContentProvider还没完成写入就被终止了,尽管putInt是同步的,但可能系统层面的处理有延迟或者异步步骤。 另外,ContentResolver的apply和commit的区别也可能相关。虽然putInt内部可能使用的是commit,但需要确认其具体实现。如果是apply的话,虽然是异步的,但根据文档,putInt应该是同步的。所以这里可能需要查看源码确认。 另外,系统服务可能在关机时被快速终止,导致即使putInt返回成功,但数据还没持久化到磁盘。因为数据库写入可能先到内存,再异步刷盘。这时候如果系统突然断电,数据就会丢失。这种情况即使在同步方法中也可能发生,因为同步只保证数据提交到数据库事务,但事务的持久化可能需要时间。 用户可能没有意识到,即使同步方法返回成功,数据可能还在内核的页面缓存中,没有真正写入磁盘存储。因此,在关机时,如果系统立即断电,这部分数据可能丢失。需要解释数据库写入的机制和持久化的保证。 此外,AndroidSettings Provider可能有自己的缓存机制,或者某些设置需要额外的步骤才能生效,比如广播或者重启服务。如果在写入后没有正确触发这些步骤,即使数据保存了,可能在下一次启动时没有正确加载。 可能的解决方案包括在写入后调用ContentResolver的update或者确保数据库立即刷盘,或者使用更底层的API,或者在关机流程中增加延迟等待数据持久化完成。但需要指出这些方法在普通应用中的可行性,因为普通应用可能没有权限修改关机流程或者访问底层API。 需要验证putInt是否确实同步写入磁盘,或者是否依赖系统服务的响应。可能SystemServer在关机时处理请求的队列被中断,导致尽管putInt返回成功,但实际上系统服务未能处理该请求。 总结,可能的原因包括:1. 系统服务在关机时被终止,导致写入未完成;2. 数据库写入到内存缓存但未刷盘;3. 设置需要额外步骤生效。需要逐一分析,并给出相应的解释和建议。</think>`Settings.System.putInt()` 确实是同步方法,理论上调用后数据会立即写入系统数据库 (`settings.db`),但在**关机流程中仍可能出现数据未保存**的情况。以下是可能原因及技术细节分析: --- ### 一、同步方法的局限性 #### 1. 数据库事务的持久化延迟 - **同步 ≠ 立即刷盘** `putInt()` 的同步性仅表示调用线程会等待数据库事务提交完成,但数据库底层可能仍存在**内核页面缓存(Page Cache)**未真正写入物理存储。Android 的 SQLite 默认使用 `PRAGMA synchronous = FULL`,但事务提交后仍需依赖系统调度将缓存数据写入磁盘。 - **关机断电导致缓存丢失** 若在数据从缓存刷入磁盘前断电,写入会丢失。这是所有文件系统面临的共性问题,并非 Android 特有。 #### 2. 系统服务的生命周期 - **Settings Provider 进程被提前终止** `Settings.System.putInt()` 的底层实现通过 Binder 调用系统服务 `SettingsProvider`(运行在 `system_server` 进程)。在关机流程中,`system_server` 可能优先被终止,导致尚未完成的数据库操作被中断。 --- ### 二、关机流程的特殊性 #### 1. 关机时序问题 Android 关机流程会触发以下关键步骤: 1. 广播 `ACTION_SHUTDOWN`,通知应用和服务保存数据; 2. 终止非关键系统服务(可能包括 `SettingsProvider`); 3. 卸载文件系统,同步缓存到磁盘; 4. 内核关闭硬件。 若 `putInt()` 调用发生在步骤 2 之后,`SettingsProvider` 已终止,写入操作将直接失败。 #### 2. 文件系统卸载的不可逆性 - **卸载文件系统后无法写入** 在关机后期,文件系统会进入只读模式或直接卸载。此时即使 `putInt()` 成功返回,底层文件操作也会因存储不可写而静默失败。 --- ### 三、验证与解决方案 #### 1. 验证数据是否真正持久化 可通过以下命令检查 `settings.db` 的修改时间: ```bash adb shell su root ls -l /data/system/users/0/settings_system.xml ``` 若关机后时间戳未更新,说明数据未写入。 #### 2. 解决方案 1. **强制同步文件系统** 在 `putInt()` 后调用 `sync` 命令强制刷盘: ```java Runtime.getRuntime().exec("sync"); ``` *注意:需要 `root` 权限,普通应用无法使用。* 2. **提前触发关机前的数据保存** 在接收到 `ACTION_SHUTDOWN` 广播时尽早执行关键数据写入: ```java BroadcastReceiver shutdownReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Settings.System.putInt(resolver, "KEY", value); } }; context.registerReceiver(shutdownReceiver, new IntentFilter(Intent.ACTION_SHUTDOWN)); ``` 3. **使用更底层的 API(需系统权限)** 系统应用可通过直接修改 `settings_system.xml` 或调用 `Settings.Global.putString()` 的 `makeDefault` 方法,强制生成默认配置文件。 --- ### 四、总结表 | 现象 | 根本原因 | 解决方案 | |--------------------|----------------------------|-----------------------------------| | 数据写入后丢失 | 内核缓存未刷盘 | 调用 `sync`(需 root) | | `putInt()` 返回失败 | SettingsProvider 进程已终止 | 提前在 `ACTION_SHUTDOWN` 阶段保存 | | 设置未生效 | 依赖服务的重启逻辑未触发 | 发送广播通知系统(如 `AIRPLANE_MODE_CHANGED`)| --- ### 示例:改进后的关机数据保存逻辑 ```java public void safeShutdownWrite(Context context) { ContentResolver resolver = context.getContentResolver(); // 1. 同步写入设置 Settings.System.putInt(resolver, "SENSITIVE_KEY", 1); // 2. 强制刷盘(需要系统权限) if (hasRootPermission()) { Runtime.getRuntime().exec("sync"); } // 3. 延迟关机确保操作完成 new Handler(Looper.getMainLooper()).postDelayed(() -> { PowerManager pm = context.getSystemService(PowerManager.class); pm.shutdown(false, "user request", false); }, 1000); // 延迟 1 秒 } ``` *注意:此代码需要系统签名或 root 权限,普通应用无法实现完整流程。* 若您需要进一步分析具体场景(如系统定制开发),可提供更多日志细节。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值