ContactCallActivatedEventArgs 類別

定義

在應用程式啟動時提供資料,以呼叫連絡人。

JAVAscript 此類型會顯示為 WebUIContactCallActivatedEventArgs

public ref class ContactCallActivatedEventArgs sealed : IActivatedEventArgs, IContactCallActivatedEventArgs
/// [Windows.Foundation.Metadata.ContractVersion(Windows.ApplicationModel.Activation.ContactActivatedEventsContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class ContactCallActivatedEventArgs final : IActivatedEventArgs, IContactCallActivatedEventArgs
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.ApplicationModel.Activation.ContactActivatedEventsContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class ContactCallActivatedEventArgs : IActivatedEventArgs, IContactCallActivatedEventArgs
Public NotInheritable Class ContactCallActivatedEventArgs
Implements IActivatedEventArgs, IContactCallActivatedEventArgs
繼承
Object Platform::Object IInspectable ContactCallActivatedEventArgs
屬性
實作

Windows 需求

裝置系列
Windows Desktop Extension SDK (已於 10.0.10240.0 引進)
API contract
Windows.ApplicationModel.Activation.ContactActivatedEventsContract (已於 v1.0 引進)

範例

以下是您處理 PSTN 號碼和 Skype Id 的連絡人通話啟用所需的程式碼範例。

protected override void OnActivated(IActivatedEventArgs args)
{
    if (args.Kind == ActivationKind.Contact)
    {
        var contactArgs = args as IContactActivatedEventArgs;
        if (contactArgs.Verb == Windows.ApplicationModel.Contacts.ContactLaunchActionVerbs.Call)
        {
            IContactCallActivatedEventArgs callArgs = contactArgs as IContactCallActivatedEventArgs;

            //get contact display info
            var contactName = callArgs.Contact.DisplayName;
            var contactThumbnail = callArgs.Contact.Thumbnail;

            if (callArgs.ServiceId == "telephone")
            {
                var phoneNumber = callArgs.ServiceUserId;
                //add calling logic for PSTN numbers
            }
            else if (callArgs.ServiceId == "skype.com")
            {
                var userId = callArgs.ServiceUserId;
                //add calling logic for Skype Ids
            }
        }
    }
}
void App::OnActivated(Windows::ApplicationModel::Activation::IActivatedEventArgs const& args)
{
    if (args.Kind() == Windows::ApplicationModel::Activation::ActivationKind::Contact)
    {
        auto contactArgs{ args.as<Windows::ApplicationModel::Activation::IContactActivatedEventArgs>() };
        if (contactArgs.Verb() == Windows::ApplicationModel::Contacts::ContactLaunchActionVerbs::Call())
        {
            auto callArgs{ contactArgs.as<Windows::ApplicationModel::Activation::ContactCallActivatedEventArgs>() };

            // Get contact display info.
            auto contactName{ callArgs.Contact().DisplayName() };
            auto contactThumbnail{ callArgs.Contact().Thumbnail() };

            if (callArgs.ServiceId() == L"telephone")
            {
                auto phoneNumber{ callArgs.ServiceUserId() };
                // Add calling logic for PSTN numbers.
            }
            else if (callArgs.ServiceId() == L"skype.com")
            {
                auto userId{ callArgs.ServiceUserId() };
                // Add calling logic for Skype Ids.
            }
        }
    }
}
void App::OnActivated(IActivatedEventArgs^ args)
{
    if (args->Kind == ActivationKind::Contact)
    {
        auto contactArgs = dynamic_cast<IContactActivatedEventArgs^>(args);
        if (contactArgs->Verb == Windows::ApplicationModel::Contacts::ContactLaunchActionVerbs::Call)
        {
            auto callArgs = dynamic_cast<ContactCallActivatedEventArgs^>(contactArgs);

            //get contact display info
            auto contactName = callArgs->Contact->DisplayName;
            auto contactThumbnail = callArgs->Contact->Thumbnail;

            if (callArgs->ServiceId == "telephone")
            {
                auto phoneNumber = callArgs->ServiceUserId;
                //add calling logic for PSTN numbers
            }
            else if (callArgs->ServiceId == "skype.com")
            {
                auto userId = callArgs->ServiceUserId;
                //add calling logic for Skype Ids
            }
        }
    }
}

備註

Windows 8.1可讓使用者從連絡人卡片或 Windows 搜尋體驗呼叫其連絡人。 藉由實作連絡人通話啟用合約,Windows 可以啟動您的應用程式來撥打使用者的電話。

若要接收通話啟用,您的應用程式必須在其資訊清單中註冊 「windows.contact」 擴充功能類別。 在此延伸模組下,您必須包含 「Verb」 屬性等於 「call」 的 「LaunchAction」 元素。然後,您可以指定 「ServiceId」 元素,以指定您支援的呼叫類型。 例如,如果您的應用程式處理標準 PSTN 通話,您可以指定 「ServiceId」 為 「telephone」。如果您的應用程式處理透過 Web 服務呼叫,例如 Skype,您可以指定該服務的功能變數名稱,例如「skype.com」。

如果有多個應用程式已註冊此合約,使用者可以選擇其中一個應用程式作為處理呼叫的預設值。

注意

若要讓使用者將您的應用程式設定為 PSTN 號碼的預設通話應用程式,您的應用程式也必須支援 「tel」 URI 配置。

以下是資訊清單註冊的範例。

<m2:Extension Category="windows.contact" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest">
  <m2:Contact>
    <m2:ContactLaunchActions>
      <m2:LaunchAction Verb="call" DesiredView="useLess">
        <m2:ServiceId>telephone</m2:ServiceId>
        <m2:ServiceId>skype.com</m2:ServiceId>
      </m2:LaunchAction>
    </m2:ContactLaunchActions>
  </m2:Contact>
</m2:Extension>

在資訊清單中註冊之後,即可針對連絡人通話合約啟用您的應用程式。 啟動應用程式時,您可以使用事件資訊來識別呼叫啟用,並擷取參數,以協助您完成使用者的呼叫。

如需如何透過連絡人動作處理應用程式啟用的資訊,請參閱 快速入門:處理連絡人動作

屬性

Contact

取得通話的連絡人。

Kind

取得啟用類型。

PreviousExecutionState

取得應用程式啟動前的執行狀態。

ServiceId

取得用於呼叫之服務的識別碼。

ServiceUserId

取得用於呼叫之服務的使用者識別碼。

SplashScreen

取得啟動顯示畫面物件,該物件提供從啟動顯示畫面轉換為啟動的應用程式的相關資訊。

Verb

取得要執行的動作。

適用於

另請參閱