VMOS Cloud API
  • 简体中文
  • English
  • 简体中文
  • English
  • 产品介绍
  • 产品类型
  • 产品计费
  • OpenAPI
    • 使用指南
    • 接口文档
    • 错误码
    • 实例属性列表
    • 安卓改机属性列表
    • 回调任务业务类型码
    • 更新日志
  • Android端 SDK
    • 示例搭建
    • 接口说明
    • 回调函数
    • 错误码
    • 更新日志
  • Web H5端 SDK
    • 示例搭建
    • 接口说明
    • H5 SDK 回调函数
    • 错误码
    • 更新日志
  • Windows PC端 SDK
    • 示例搭建
    • 接口说明
    • 回调函数
    • 更新日志
  • 端侧与云机通信开发
    • AIDL接入方式
    • 系统服务API(aidl)
  • 类XP、LSP Hook框架
    • 类Xposed、LSPosed框架
    • 传感器数据动态仿真
  • 相关协议

端侧与云机通信开发(AIDL 方式)

1. 在项目 app 目录下的 build.gradle 开启 AIDL

以 build.gradle.kts 为例:

android {
    // ...
    // 开启 AIDL
    buildFeatures {
        aidl = true
    }
}

2. 创建 aidl 文件

  1. 在 app/src/main 目录下创建 aidl 文件夹。
  2. 下载 AIDL 压缩包并解压到该目录(完整路径为 aidl.cloud.api.server)。

AIDL 文件下载:
点击下载 aidl.zip

3. 在 app 项目中连接 aidl 服务

以 Kotlin 代码为例:

// 1. 创建 ServiceConnection
private val mControl = object : ServiceConnection {
    override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
        LogUtils.d("创建 Control AIDL")
        control = ControlInterface.Stub.asInterface(service)
        MyAidlManager.setControlAidl(control)
    }

    override fun onServiceDisconnected(name: ComponentName?) {
        LogUtils.d("Control AIDL 断开连接")
        // 断开后延迟重连
        GlobalScope.launch {
            delay(3000)
            startMyService()
        }
    }
}

private val mRoot = object : ServiceConnection {
    override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
        LogUtils.d("创建 Root AIDL")
        root = RootInterface.Stub.asInterface(service)
        MyAidlManager.setRootAidl(root)
    }

    override fun onServiceDisconnected(name: ComponentName?) {
        LogUtils.d("Root AIDL 断开连接")
        // 断开后延迟重连
        GlobalScope.launch {
            delay(3000)
            startMyService()
        }
    }
}

// 2. 全局单例管理 AIDL 接口
object MyAidlManager {
    var control: ControlInterface? = null
    var root: RootInterface? = null

    fun setControlAidl(control: ControlInterface?) {
        this.control = control
    }

    fun setRootAidl(root: RootInterface?) {
        this.root = root
    }
}

// 3. 绑定 AIDL 服务
private fun startMyService() {
    val intentControl = Intent("aidl.cloud.api.ControlServer").apply {
        setPackage("com.cloud.rtcgesture")
    }
    bindService(intentControl, mControl, BIND_AUTO_CREATE)

    val intentRoot = Intent("aidl.cloud.api.RootServer").apply {
        setPackage("com.cloud.rtcgesture")
    }
    bindService(intentRoot, mRoot, BIND_AUTO_CREATE)
}

// 4. 解绑服务(建议在 Activity/Service 的 onDestroy 中调用)
override fun onDestroy() {
    super.onDestroy()
    unbindService(mControl)
    unbindService(mRoot)
}

// 5. 启动服务(通常在合适时机调用,例如 Application 或 Activity onCreate)
startMyService()

4. 在 APP 目录下的 AndroidManifest.xml 添加适配

<manifest>
    <!-- ... -->

    <queries>
        <package android:name="com.cloud.rtcgesture" />
    </queries>

</manifest>

完成以上步骤后,即可在 Android 端通过 AIDL 与云机服务进行通信。

AIDL文件下载

点击下载(aidl.zip)

Prev
Windows PC端 SDK
Next
类XP、LSP Hook框架