gpt4 book ai didi

android - 通过 luajava 获取 Android 系统设置

转载 作者:行者123 更新时间:2023-11-29 02:22:29 30 4
gpt4 key购买 nike

我正在尝试在 XPrivacyLua 自定义 Hook 中获取系统设置的值。

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:clsACCESSIBILITY_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 值的正确语法是什么?

最佳答案

我给 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

关于android - 通过 luajava 获取 Android 系统设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54506649/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com