End-Side Communication with Cloud Phone (AIDL Method)
1. Enable AIDL in Project's app/build.gradle
Example with build.gradle.kts:
android {
// ...
// Enable AIDL
buildFeatures {
aidl = true
}
}
2. Create AIDL Files
- Create an
aidlfolder under theapp/src/maindirectory. - Download the AIDL package and extract it to this directory (full path:
aidl.cloud.api.server).
AIDL File Download:
Click to download aidl.zip
3. Connect to AIDL Service in App Project
Example in Kotlin:
// 1. Create ServiceConnection
private val mControl = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
LogUtils.d("Created Control AIDL")
control = ControlInterface.Stub.asInterface(service)
MyAidlManager.setControlAidl(control)
}
override fun onServiceDisconnected(name: ComponentName?) {
LogUtils.d("Control AIDL disconnected")
// Reconnect with delay after disconnection
GlobalScope.launch {
delay(3000)
startMyService()
}
}
}
private val mRoot = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
LogUtils.d("Created Root AIDL")
root = RootInterface.Stub.asInterface(service)
MyAidlManager.setRootAidl(root)
}
override fun onServiceDisconnected(name: ComponentName?) {
LogUtils.d("Root AIDL disconnected")
// Reconnect with delay after disconnection
GlobalScope.launch {
delay(3000)
startMyService()
}
}
}
// 2. Global Singleton for Managing AIDL Interfaces
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. Bind AIDL Services
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. Unbind Services (Recommended to call in Activity/Service onDestroy)
override fun onDestroy() {
super.onDestroy()
unbindService(mControl)
unbindService(mRoot)
}
// 5. Start Services (Usually call at appropriate time, e.g., in Application or Activity onCreate)
startMyService()
4. Add Adaptation in App's AndroidManifest.xml
<manifest>
<!-- ... -->
<queries>
<package android:name="com.cloud.rtcgesture" />
</queries>
</manifest>
After completing the above steps, you can communicate with the cloud phone service via AIDL on the Android side.
### AIDL File Download
[Click to download (aidl.zip)](/vmoscloud/doc/aidl.zip)