DSBridge supports Progress Callback, allowing a single native call to return multiple values to JavaScript (e.g., for download progress).
In Java, use handler.setProgressData(data) to send intermediate updates and handler.complete(data) to finish the call. In JavaScript, the callback function will be triggered for every update.
// Java implementation
@JavascriptInterface
public void callProgress(Object args, final CompletionHandler<Integer> handler) {
new CountDownTimer(11000, 1000) {
int i=10;
@Override
public void onTick(long millisUntilFinished) {
// Send progress data multiple times
handler.setProgressData((i--));
}
@Override
public void onFinish() {
// Complete the invocation
handler.complete(0);
}
}.start();
}
// JavaScript usage
dsBridge.call("callProgress", function (value) {
document.getElementById("progress").innerText = value
})