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 : IPhoneLineWatcherpublic sealed class PhoneLineWatcher : IPhoneLineWatcherPublic NotInheritable Class PhoneLineWatcher Implements IPhoneLineWatcher// You can use this class in JavaScript.
Attributes
Windows 10 requirements
Device family
Windows Mobile Extension SDK (introduced v10.0.10240.0)
API contract
Windows.ApplicationModel.Calls.CallsPhoneContract (introduced v1)

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

Get the current status of the PhoneLineWatcher instance.

public : PhoneLineWatcherStatus Status { get; }public PhoneLineWatcherStatus Status { get; }Public ReadOnly Property Status As PhoneLineWatcherStatus// You can use this property in JavaScript.

Methods

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

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

public : void Start()public void Start()Public Function Start() As void// You can use this method in JavaScript.

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

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

public : void Stop()public void Stop()Public Function Stop() As void// You can use this method in JavaScript.

Events

EnumerationCompleted EnumerationCompleted EnumerationCompleted EnumerationCompleted

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

public : event TypedEventHandler EnumerationCompleted<PhoneLineWatcher,  object>public event TypedEventHandler EnumerationCompleted<PhoneLineWatcher,  object>Public Event EnumerationCompleted<PhoneLineWatcher,  object>// You can use this event in JavaScript.

Remarks

Phone lines can be added, removed, or updated to a device at any time. This event only indicates that an enumeration of the phone lines has been completed at a given point in time.

This event is only generated once per PhoneLineWatcher instance.

LineAdded LineAdded LineAdded LineAdded

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

public : event TypedEventHandler LineAdded<PhoneLineWatcher,  PhoneLineWatcherEventArgs>public event TypedEventHandler LineAdded<PhoneLineWatcher,  PhoneLineWatcherEventArgs>Public Event LineAdded<PhoneLineWatcher,  PhoneLineWatcherEventArgs>// You can use this event in JavaScript.

LineRemoved LineRemoved LineRemoved LineRemoved

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

public : event TypedEventHandler LineRemoved<PhoneLineWatcher,  PhoneLineWatcherEventArgs>public event TypedEventHandler LineRemoved<PhoneLineWatcher,  PhoneLineWatcherEventArgs>Public Event LineRemoved<PhoneLineWatcher,  PhoneLineWatcherEventArgs>// You can use this event in JavaScript.

Remarks

In general, cellular lines can never be removed. This event is more likely to occur when a VoIP line is removed, which typically happens when the associated applications is uninstalled.

LineUpdated LineUpdated LineUpdated LineUpdated

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

public : event TypedEventHandler LineUpdated<PhoneLineWatcher,  PhoneLineWatcherEventArgs>public event TypedEventHandler LineUpdated<PhoneLineWatcher,  PhoneLineWatcherEventArgs>Public Event LineUpdated<PhoneLineWatcher,  PhoneLineWatcherEventArgs>// You can use this event in JavaScript.

Remarks

Cases where a phone line is updated include when the metadata for a phone line changes, such as with voice mail count or registration status.

Stopped Stopped Stopped Stopped

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

public : event TypedEventHandler Stopped<PhoneLineWatcher,  object>public event TypedEventHandler Stopped<PhoneLineWatcher,  object>Public Event Stopped<PhoneLineWatcher,  object>// You can use this event in JavaScript.