IDL Service connectRemoteAbility failed, errorCode is 1203
报错日志如下:
I 02D03/HiTraceC: [10c674ed12beeb5, 0, 0] HiTraceBegin name:connectAbility flags:1.
W 01510/BinderInvoker: SendRequest: handle=<private> ,flags:<private>
E 02D03/HiTraceC: [10c674ed12beeb5, 0, 0] HiTraceEnd error: invalid end id.
I 01100/AppExecFwk: [10c674ed12beeb5, 0, 0] ContextDeal::connectRemoteAbility called
W 01510/BinderInvoker: [10c674ed12beeb5, 0, 0] SendRequest: handle=<private> ,flags:<private>
E 01510/IPCObjectStub: [10c674ed12beeb5, 3fa4023, b04a10] IPCObjectStub::ProcessProto called, type = 0, normal stub object
W 01100/AbilityShell: [10c674ed12beeb5, 0, 0] DistributedManager::sendRequest waitTime result code is 1203
E 01100/AppExecFwk: [10c673eb900c33c, 0, 0] Context::connectRemoteAbility failed, errorCode is 1203
E 02D03/HiTraceC: [10c674ed12beeb5, 0, 0] HiTraceEnd error: invalid end id.
E 01100/AppKit: [10c674ed12beeb5, 0, 0] ContextDeal::connectAbility called failed
I 02D03/HiTraceC: [10c674ed12beeb5, 0, 0] HiTraceEnd.
E 01310/O0000Oo: connect ability failed, connWrap: ohos.aafwk.ability.O000000@4112d9b
通过如下方式建立IDL连接失败:
Intent intent = new Intent();
Operation operation = new Intent.OperationBuilder()
.withDeviceId("deviceId")
.withBundleName("com.example.test")
.withAbilityName("com.example.test.TestService")
.build();
intent.setOperation(operation);
connectAbility(intent, new IAbilityConnection() {
……
}
"com.example.test.TestService"的config.json配置如下:
"abilities": [
{
"backgroundModes": [
"dataTransfer",
"location"
],
"name": "com.example.test.TestService",
"icon": "$media:icon",
"description": "$string:testservice_description",
"type": "service",
"process": ".TestService",
"visible": true
}
]
"com.example.test.TestService"的启动在MainAbility.java的onStart()中:
Intent newIntent = new Intent();
Operation operation = new Intent.OperationBuilder()
.withDeviceId("deviceId")
.withBundleName("com.example.test")
.withAbilityName("com.example.test.TestService")
.build();
newIntent.setOperation(operation);
startAbility(newIntent);
原因是没有理解启动本地服务和启动远程服务的区别
启动本地设备Service的代码示例如下:
Intent intent = new Intent();
Operation operation = new Intent.OperationBuilder()
.withDeviceId("")
.withBundleName("com.huawei.hiworld.himusic")
.withAbilityName("com.huawei.hiworld.himusic.entry.ServiceAbility")
.build();
intent.setOperation(operation);
startAbility(intent);
因为我是做本地服务的IDL通信,所以要选择空的.withDeviceId(“”)。
启动远程设备Service的代码示例如下:
Operation operation = new Intent.OperationBuilder()
.withDeviceId("deviceId")
.withBundleName("com.huawei.hiworld.himusic")
.withAbilityName("com.huawei.hiworld.himusic.entry.ServiceAbility")
.withFlags(Intent.FLAG_ABILITYSLICE_MULTI_DEVICE) // 设置支持分布式调度系统多设备启动的标识
.build();
Intent intent = new Intent();
intent.setOperation(operation);
startAbility(intent);
当调用connectAbility()接口时,定义operation使用.withDeviceId()要与startAbility()时保持一致。