Dr. Yatish Bathla
Dr. Yatish Bathla

Reputation: 522

How to use Settings.Global, Settings.Secure and Settings.System in Android?

I want to use above mentioned classes and want to retrieve information from their static Constants. I want to retrieve information like this. For example from Settings.Secure

SETTINGS_SECURE
ADB_ENABLED=1
ALLOWED_GEOLOCATION_ORIGINS=http://www.google.co.uk 
ALLOW_MOCK_LOCATION=0
ANDROID_ID=200142d4dfd4e641

But I am actually getting this Output:

SETTINGS_SECURE
ADB_ENABLED=adb_enabled
ALLOWED_GEOLOCATION_ORIGINS=allowed_geolocation_origins
ALLOW_MOCK_LOCATION=allow_mock_location
ANDROID_ID=android_id

Any Suggestions?

Upvotes: 1

Views: 2348

Answers (1)

Mike M.
Mike M.

Reputation: 39201

It looks like you're just retrieving the constants' values. As a quick example that will illustrate the difference, to produce the above output:

StringBuilder sb = new StringBuilder("SETTINGS_SECURE\n");

sb.append(Settings.Secure.ADB_ENABLED.toUpperCase())
    .append("=")
    .append(Settings.Secure.getString(getContentResolver(),
        Settings.Secure.ADB_ENABLED))
    .append("\n")

    .append(Settings.Secure.ALLOWED_GEOLOCATION_ORIGINS.toUpperCase())
    .append("=")
    .append(Settings.Secure.getString(getContentResolver(),
        Settings.Secure.ALLOWED_GEOLOCATION_ORIGINS))
    .append("\n")

    .append(Settings.Secure.ALLOW_MOCK_LOCATION.toUpperCase())
    .append("=")
    .append(Settings.Secure.getString(getContentResolver(),
        Settings.Secure.ALLOW_MOCK_LOCATION))
    .append("\n")

    .append(Settings.Secure.ANDROID_ID.toUpperCase())
    .append("=")
    .append(Settings.Secure.getString(getContentResolver(),
        Settings.Secure.ANDROID_ID));

Upvotes: 1

Related Questions