我正在尝试从XPrivacyLua自定义挂钩中获取系统设置的值。
Settings.Secure | Android Developers #getInt()
function after(hook, param)
local result = param:getResult()
if result == null or result:getItemCount() == 0 then
return false
end
--
local context = param:getApplicationContext()
local cls = luajava.bindClass('android.provider.Settings$Secure')
local isColorInverted = cls:getInt(context, cls:ACCESSIBILITY_DISPLAY_INVERSION_ENABLED)
if isColorInverted == 1 then
return true
end
--
local fake = result:newPlainText('XPrivacyLua', 'Private')
param:setResult(fake)
return true
end
尝试1: cls :
ACCESSIBILITY_DISPLAY_INVERSION_ENABLED
local isColorInverted = cls:getInt(context, cls:ACCESSIBILITY_DISPLAY_INVERSION_ENABLED)
-- [string "script"]:9: function arguments expected
尝试2: cls .
ACCESSIBILITY_DISPLAY_INVERSION_ENABLED
local isColorInverted = cls:getInt(context, cls.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED)
-- Exception:
-- org.luaj.vm2.LuaError: script:9 no coercible public method at org.luaj.vm2.LuaValue.error(SourceFile:1041)
-- ...
-- <full stack trace>
尝试3: ACCESSIBILITY_DISPLAY_INVERSION_ENABLED
local isColorInverted = cls:getInt(context, ACCESSIBILITY_DISPLAY_INVERSION_ENABLED)
-- Same as attempt 2
在luajava中获取ACCESSIBILITY_DISPLAY_INVERSION_ENABLED
值的正确语法是什么?
答案 0 :(得分:0)
我对getInt
的第一个参数是错误的。
它要求使用ContentResolver,而我将其传递给ApplicationContext。
下面是工作代码。
function after(hook, param)
local result = param:getResult()
if result == null or result:getItemCount() == 0 then
return false
end
--
local context = param:getApplicationContext()
local cr = context:getContentResolver()
local cls = luajava.bindClass('android.provider.Settings$Secure')
local isColorInverted = cls:getInt(cr, ACCESSIBILITY_DISPLAY_INVERSION_ENABLED)
if isColorInverted == 1 then
return true
end
--
local fake = result:newPlainText('XPrivacyLua', 'Private')
param:setResult(fake)
return true
end