我试图在XPrivacyLua自定义钩子中获取系统设置的值。
Settings.Secure \ Android开发人员#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
endcls:ACCESSIBILITY_DISPLAY_INVERSION_ENABLED:尝试1:
local isColorInverted = cls:getInt(context, cls:ACCESSIBILITY_DISPLAY_INVERSION_ENABLED)
-- [string "script"]:9: function arguments expectedcls.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED 尝试2:
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值的正确语法是什么?
发布于 2019-02-03 21:00:07
我对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
endhttps://stackoverflow.com/questions/54506649
复制相似问题