mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 09:45:19 +08:00
Added injectModuleAppResources on Resources function in YukiHookFactory
This commit is contained in:
@@ -114,17 +114,21 @@ val Context.processName: String
|
||||
fun Context.injectModuleAppResources()
|
||||
```
|
||||
|
||||
```kotlin
|
||||
fun Resources.injectModuleAppResources()
|
||||
```
|
||||
|
||||
**变更记录**
|
||||
|
||||
`v1.0.93` `新增`
|
||||
|
||||
**功能描述**
|
||||
|
||||
> 向 Hook APP (宿主) `Context` 注入当前 Xposed 模块的资源。
|
||||
> 向 Hook APP (宿主) `Context` 或 `Resources` 注入当前 Xposed 模块的资源。
|
||||
|
||||
注入成功后,你就可以直接使用例如 `ImageView.setImageResource` 或 `Resources.getString` 装载当前 Xposed 模块的资源 ID。
|
||||
|
||||
注入的资源作用域仅限当前 `Context`,你需要在每个用到宿主 `Context` 的地方重复调用此方法进行注入才能使用。
|
||||
注入的资源作用域仅限当前 `Context` 或 `Resources`,你需要在每个用到宿主 `Context` 或 `Resources` 的地方重复调用此方法进行注入才能使用。
|
||||
|
||||
为防止资源 ID 互相冲突,你需要在当前 Xposed 模块项目的 `build.gradle` 中修改资源 ID。
|
||||
|
||||
@@ -158,8 +162,10 @@ injectMember {
|
||||
}
|
||||
afterHook {
|
||||
instance<Activity>().also {
|
||||
// 注入模块资源
|
||||
// <方案1> 通过 Context 注入模块资源
|
||||
it.injectModuleAppResources()
|
||||
// <方案2> 直接得到宿主 Resources 注入模块资源
|
||||
it.resources.injectModuleAppResources()
|
||||
// 直接使用模块资源 ID
|
||||
it.getString(R.id.app_name)
|
||||
}
|
||||
@@ -175,7 +181,10 @@ injectMember {
|
||||
onAppLifecycle {
|
||||
onCreate {
|
||||
// 全局注入模块资源,但仅限于全局生命周期,类似 ImageView.setImageResource 这样的方法在 Activity 中需要单独注入
|
||||
// <方案1> 通过 Context 注入模块资源
|
||||
injectModuleAppResources()
|
||||
// <方案2> 直接得到宿主 Resources 注入模块资源
|
||||
resources.injectModuleAppResources()
|
||||
// 直接使用模块资源 ID
|
||||
getString(R.id.app_name)
|
||||
}
|
||||
|
Reference in New Issue
Block a user