SDK事件(Java)
描述
当初始化SDK时,可以在ClientConfig
对象中提供可选的OnDeviceDecisioningHandler
对象。 它可用于订阅SDK内发生的各种事件。 例如,onDeviceDecisioningReady
事件可与回调函数一起使用,在SDK准备好进行方法调用时,将调用该回调函数。
事件
OnDeviceDecisioningHandler
对象包含以下回调,这些回调是为某些事件调用的:
名称
参数
描述
DevicedecisioningReady
无
在客户端第一次为on-device decisioning准备就绪时只调用一次
artifactDownloadSucceeded
工件文件的字节[]内容
每次下载on-device decisioning工件时调用
artifactDownloadFailed
例外
每次下载on-device decisioning工件失败时调用
示例
SDK事件
ClientConfig clientConfig = ClientConfig.builder()
.client("acmeclient")
.organizationId("1234567890@AdobeOrg")
.defaultDecisioningMethod(DecisioningMethod.ON_DEVICE)
.onDeviceDecisioningHandler(new OnDeviceDecisioningHandler() {
@Override
public void onDeviceDecisioningReady() {
// make getOffers requests
makeTargetRequests();
}
@Override
public void artifactDownloadSucceeded(byte[] artifactData) {
System.out.println("The artifact was successfully downloaded.");
}
@Override
public void artifactDownloadFailed(TargetClientException e) {
System.out.println("The artifact failed to download.");
}
}).build();
TargetClient targetJavaClient = TargetClient.create(clientConfig);
void makeTargetRequests() {
List<MboxRequest> mboxRequests = new ArrayList<>();
mboxRequests.add((MboxRequest) new MboxRequest().name("a1-serverside-ab").index(1));
TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder()
.context(new Context().channel(ChannelType.WEB))
.execute(new ExecuteRequest().setMboxes(mboxRequests))
.build();
TargetDeliveryResponse targetResponse = targetJavaClient.getOffers(targetDeliveryRequest);
}
recommendation-more-help
6906415f-169c-422b-89d3-7118e147c4e3