如何在Android中使用Settings.Global,Settings.Secure和Settings.System?

时间:2014-03-19 04:22:52

标签: java android

我想使用上面提到的类,并希望从静态常量中检索信息。我想要检索这样的信息。例如来自Settings.Secure

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

但我实际上得到了这个输出:

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

任何建议?

1 个答案:

答案 0 :(得分:1)

看起来你只是检索常数'值。作为一个快速示例,将说明差异,以产生上述输出:

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));