【HarmonyOS】IDL Service connectRemoteAbility failed, errorCode is 1203

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()时保持一致。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值