使用put/get取得或設定Android Settings.Global數值

若有需要讀寫Android系統內Java所儲存的global數值,以下以display_outputmode_auto作為範例


取得

settings get global display_outputmode_auto

設置

settings put global display_outputmode_auto 1
settings put global display_outputmode_auto 0

問題

如果出現下面錯誤表示需要高於system的權限
settings put global display_outputmode_auto 1
Error while accessing settings provider
java.lang.SecurityException: null from uid 1000 not allowed to perform WRITE_SETTINGS
    at android.os.Parcel.readException(Parcel.java:1465)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
    at android.content.ContentProviderProxy.call(ContentProviderNative.java:636)
    at com.android.commands.settings.SettingsCmd.putForUser(SettingsCmd.java:208)
    at com.android.commands.settings.SettingsCmd.run(SettingsCmd.java:137)
    at com.android.commands.settings.SettingsCmd.main(SettingsCmd.java:55)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:243)
    at dalvik.system.NativeStart.main(Native Method)

留言