【问题标题】:accessing aidl to consume the custom service apis + android访问aidl消费自定义服务apis + android
【发布时间】:2021-05-18 06:53:11
【问题描述】:

在框架级别有一个服务,它们仅从框架绑定和启动该服务。我需要访问该服务并从客户端(Android)端使用这些 API。我已经浏览了大多数示例,这些示例具有用于从客户端创建/启动服务连接的代码,并且每当使用 IBinder 在该连接的侦听器中连接服务时,我们都可以访问这些 API。 我试过了,比如在客户端添加具有相同包结构的aidl文件并添加以下代码。

val DevManager =applicationContext.getSystemService("servicename")
        val clazz = Class.forName(DevManager.javaClass.name)
        val method = DevManager.javaClass.getDeclaredMethod(
            "getIDevManager",
            Context::class.java
        )
        method.isAccessible = true
        val DevService: IDevManager =
            method.invoke(DevManager) as IDevManager
        var status = DevManager.devStatus

我们得到 NoSuchMethodException。 请建议我们如何实现这一点,在此先感谢。

【问题讨论】:

    标签: android frameworks aidl


    【解决方案1】:
    try {
            val testManager = TestApplication.context!!.getSystemService(SERVICE_NAME)
    
            val status = testManager.javaClass.getDeclaredMethod("methodName")
            status.isAccessible = true
            result = (status.invoke(testManager)).toString()
        } catch (e: Exception) {
            Log.d(TAG, " exception: ${e.message}")
            e.printStackTrace()
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-03
      • 2018-02-12
      • 1970-01-01
      • 2022-12-29
      • 2012-04-05
      • 2015-02-10
      • 1970-01-01
      相关资源
      最近更新 更多