PhoneLineWatcher Class

Definition

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

public ref class PhoneLineWatcher sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.ApplicationModel.Calls.CallsPhoneContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class PhoneLineWatcher final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.ApplicationModel.Calls.CallsPhoneContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class PhoneLineWatcher
Public NotInheritable Class PhoneLineWatcher
Inheritance
Object Platform::Object IInspectable PhoneLineWatcher
Attributes

Windows requirements

Device family
Windows Mobile Extension SDK (introduced in 10.0.10240.0)
API contract
Windows.ApplicationModel.Calls.CallsPhoneContract (introduced in v1.0)
App capabilities
phoneCallHistory phoneCallHistorySystem

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

Get the current status of the PhoneLineWatcher instance.

Methods

Start()

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

Stop()

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

Events

EnumerationCompleted

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

LineAdded

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

LineRemoved

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

LineUpdated

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

Stopped

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

Applies to