PhoneLineWatcher PhoneLineWatcher PhoneLineWatcher PhoneLineWatcher PhoneLineWatcher Class

Definition

Represents a class that monitors for new/removed/updated phone lines on the device and notifies listeners about any changes.

public : sealed class PhoneLineWatcher
struct winrt::Windows::ApplicationModel::Calls::PhoneLineWatcher
public sealed class PhoneLineWatcher
Public NotInheritable Class PhoneLineWatcher
// This class does not provide a public constructor.
Attributes

Windows 10 requirements

Device family
Windows Mobile Extension SDK (introduced v10.0.10240.0)
API contract
Windows.ApplicationModel.Calls.CallsPhoneContract (introduced v1)
Capabilities
phoneCallHistorySystem phoneCallHistory

Remarks

A phone line is a line that a user can use to either receive inbound or place outbound phone calls. A single device can have multiple lines. For example, the system creates a separate line specifically for VoIP applications that enables initiating an outbound call.

The system automatically detects the available lines on boot and then dynamically detects lines as lines are created or changed. The PhoneLineWatcher class provides a mechanism for applications to receive events as new phone lines are detected and react to the changes.

This class implements the watcher pattern.

You can retrieve an instance of this class by calling RequestLineWatcher.

The following example shows how to enumerate through all the current phone lines.

private async Task<Dictionary<Guid, PhoneLine>> GetPhoneLinesAsync()
{
    PhoneCallStore store = await PhoneCallManager.RequestStoreAsync();

    // Start the PhoneLineWatcher
    var watcher = store.RequestLineWatcher();
    var phoneLines = new List<PhoneLine>();
    var lineEnumerationCompletion = new TaskCompletionSource<bool>();
    watcher.LineAdded += async (o, args) => { var line = await PhoneLine.FromIdAsync(args.LineId); phoneLines.Add(line); };
    watcher.Stopped += (o, args) => lineEnumerationCompletion.TrySetResult(false);
    watcher.EnumerationCompleted += (o, args) => lineEnumerationCompletion.TrySetResult(true);
    watcher.Start();

    // Wait for enumeration completion
    if (!await lineEnumerationCompletion.Task)
    {
        throw new Exception("Phone Line Enumeration failed");
    }

    watcher.Stop();

    Dictionary<Guid, PhoneLine> returnedLines = new Dictionary<Guid, PhoneLine>();

    foreach (PhoneLine phoneLine in phoneLines)
    {
        if (phoneLine != null && phoneLine.Transport == PhoneLineTransport.Cellular)
        {
            returnedLines.Add(phoneLine.Id, phoneLine);
        }
    }

    return returnedLines;
}

Properties

Status Status Status Status Status

Get the current status of the PhoneLineWatcher instance.

Methods

Start() Start() Start() Start() Start()

Starts listening for changes to the phone lines on the device.

Stop() Stop() Stop() Stop() Stop()

Stops listening for changes to the phone lines on the device.

Events

EnumerationCompleted EnumerationCompleted EnumerationCompleted EnumerationCompleted EnumerationCompleted

Occurs when the PhoneLineWatcher instance completes an enumeration of all the phone lines on the device.

LineAdded LineAdded LineAdded LineAdded LineAdded

Occurs when the PhoneLineWatcher instance detects a new phone line on the device.

LineRemoved LineRemoved LineRemoved LineRemoved LineRemoved

Occurs when the PhoneLineWatcher instance detects that a phone line has been removed from the device.

LineUpdated LineUpdated LineUpdated LineUpdated LineUpdated

Occurs when the PhoneLineWatcher instance detects that a phone line has been updated on the device.

Stopped Stopped Stopped Stopped Stopped

Occurs when the PhoneLineWatcher instance stops monitoring the device for changes to the phone lines.