藍芽呼叫控制樣本藍芽CallControl樣本示範了如何配置預設的藍芽通訊裝置,用於處理調用。這個樣本使用JavaScript編寫,也需要瞭解HTML,Windows事件和事件處理常式。(function () {
// Initialize the call control object here using the default bluetooth communications device
var callControls = null;
var callToken;
var audiotag;
function id(elementId) {
return document.getElementById(elementId);
}
function initDevice() {
if (!callControls) {
callControls = Windows.Media.Devices.CallControl.getDefault();
if (callControls) {
// Add the event listener to listen for the various button presses
callControls.addEventListener("answerrequested", answerButton, false);
callControls.addEventListener("hanguprequested", hangupButton, false);
callControls.addEventListener("audiotransferrequested", audiotransferButton, false);
callControls.addEventListener("redialrequested", redialButton, false);
callControls.addEventListener("dialrequested", dialButton, false);
sdkSample.displayStatus("Call Controls Initialized");
id("scenario1Ring").disabled = false;
id("scenario1Initialize").disabled = true;
} else {
sdkSample.displayError("No Bluetooth device detected.");
}
}
}
function newIncomingCall() {
// Indicate a new incoming call and ring the headset.
callToken = callControls.indicateNewIncomingCall(true, "5555555555");
sdkSample.displayStatus("Call Token: " + callToken);
id("scenario1Ring").disabled = true;
}
function answerButton() {
// When the answer button is pressed indicate to the device that the call was answered
// and start a song on the headset (this is done by streaming music to the bluetooth
// device in this sample)
sdkSample.displayStatus("Answer requested: " + callToken);
callControls.indicateActiveCall(callToken);
audiotag = document.getElementById("audiotag");
audiotag.play();
}
function hangupButton() {
// Hang up request received. The application should end the active call and stop
// streaming to the headset
sdkSample.displayStatus("Hangup requested");
callControls.endCall(callToken);
audiotag = document.getElementById("audiotag");
audiotag.pause();
id("scenario1Ring").disabled = false;
}
function audiotransferButton() {
// Handle the audio transfer request here
sdkSample.displayStatus("Audio Transfer requested");
}
function redialButton(redialRequestedEventArgs) {
// Handle the redial request here. Indicate to the device that the request was handled.
sdkSample.displayStatus("Redial requested");
redialRequestedEventArgs.handled();
}
function dialButton(dialRequestedEventArgs) {
// A device may send a dial request by either sending a URI or if it is a speed dial,
// an integer with the number to dial.
if (typeof(dialRequestedEventArgs.contact) === "number") {
sdkSample.displayStatus("Dial requested: " + dialRequestedEventArgs.contact);
dialRequestedEventArgs.handled();
}
else {
sdkSample.displayStatus("Dial requested: " + dialRequestedEventArgs.contact.schemeName + ":" +
dialRequestedEventArgs.contact.path);
dialRequestedEventArgs.handled();
}
}
function initialize() {
id("scenario1Initialize").addEventListener("click", initDevice, false);
id("scenario1Ring").addEventListener("click", newIncomingCall, false);
id("scenarios").addEventListener("change", onScenarioChanged, false);
}
function onScenarioChanged() {
sdkSample.displayStatus("");
}
document.addEventListener("DOMContentLoaded", initialize, false);
})();
完整樣本 /Files/risk/windows8/藍芽呼叫控制sample.rar