연락처 카드의 작업에 앱 연결

연락처 카드 또는 미니 연락처 카드의 작업 옆에 사용자의 앱이 표시될 수 있습니다. 사용자는 앱을 선택하여 프로필 페이지 열기, 전화 걸기, 메시지 보내기 등의 작업을 수행할 수 있습니다.

Contact card and mini contact card

시작하려면 기존 연락처를 찾거나 새 연락처를 만듭니다. 다음으로, 주석 및 몇 가지 패키지 매니페스트 항목을 만들어 앱이 지원하는 작업을 설명합니다. 그런 다음 작업을 수행하는 코드를 작성합니다.

보다 완전한 샘플은 연락처 카드 통합 샘플을 참조하세요.

연락처 검색 또는 만들기

앱으로 다른 사용자와 연결하는 데 도움이 되는 경우 Windows에서 연락처를 검색한 다음 주석을 추가합니다. 앱에서 연락처를 관리하는 경우 해당 연락처를 Windows 연락처 목록에 추가한 다음 주석을 달 수 있습니다.

연락처 검색

이름, 이메일 주소 또는 전화 번호를 사용하여 연락처를 찾습니다.

ContactStore contactStore = await ContactManager.RequestStoreAsync();

IReadOnlyList<Contact> contacts = null;

contacts = await contactStore.FindContactsAsync(emailAddress);

Contact contact = contacts[0];

연락처 만들기

앱이 주소록과 더 유사한 경우 연락처를 만든 후에 연락처 목록에 추가합니다.

Contact contact = new Contact();
contact.FirstName = "TestContact";

ContactEmail email = new ContactEmail();
email.Address = "TestContact@contoso.com";
email.Kind = ContactEmailKind.Other;
contact.Emails.Add(email);

ContactPhone phone = new ContactPhone();
phone.Number = "4255550101";
phone.Kind = ContactPhoneKind.Mobile;
contact.Phones.Add(phone);

ContactStore store = await
    ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

ContactList contactList;

IReadOnlyList<ContactList> contactLists = await store.FindContactListsAsync();

if (0 == contactLists.Count)
    contactList = await store.CreateContactListAsync("TestContactList");
else
    contactList = contactLists[0];

await contactList.SaveContactAsync(contact);

각 연락처에 주석으로 태그 지정

앱에서 수행할 수 있는 작업 목록으로 각 연락처에 태그를 지정합니다(예: 영상 통화 및 메시징).

그런 다음, 연락처의 ID를 앱이 내부에서 해당 사용자를 식별하는 데 사용하는 ID에 연결합니다.

ContactAnnotationStore annotationStore = await
   ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

ContactAnnotationList annotationList;

IReadOnlyList<ContactAnnotationList> annotationLists = await annotationStore.FindAnnotationListsAsync();
if (0 == annotationLists.Count)
    annotationList = await annotationStore.CreateAnnotationListAsync();
else
    annotationList = annotationLists[0];

ContactAnnotation annotation = new ContactAnnotation();
annotation.ContactId = contact.Id;
annotation.RemoteId = "user22";

annotation.SupportedOperations = ContactAnnotationOperations.Message |
  ContactAnnotationOperations.AudioCall |
  ContactAnnotationOperations.VideoCall |
 ContactAnnotationOperations.ContactProfile;

await annotationList.TrySaveAnnotationAsync(annotation);

각 작업에 등록

패키지 매니페스트에서 주석에 나열된 각 작업에 등록합니다.

매니페스트의 Extensions 요소에 프로토콜 처리기를 추가하여 등록합니다.

<Extensions>
  <uap:Extension Category="windows.protocol">
    <uap:Protocol Name="ms-contact-profile">
      <uap:DisplayName>TestProfileApp</uap:DisplayName>
    </uap:Protocol>
  </uap:Extension>
  <uap:Extension Category="windows.protocol">
    <uap:Protocol Name="ms-ipmessaging">
      <uap:DisplayName>TestMsgApp</uap:DisplayName>
    </uap:Protocol>
  </uap:Extension>
  <uap:Extension Category="windows.protocol">
    <uap:Protocol Name="ms-voip-video">
      <uap:DisplayName>TestVideoApp</uap:DisplayName>
    </uap:Protocol>
  </uap:Extension>
  <uap:Extension Category="windows.protocol">
    <uap:Protocol Name="ms-voip-call">
      <uap:DisplayName>TestCallApp</uap:DisplayName>
    </uap:Protocol>
  </uap:Extension>
</Extensions>

Visual Studio에서 매니페스트 디자이너의 선언 탭에서도 이를 추가할 수 있습니다.

Declarations tab of the manifest designer

연락처 카드에서 작업 옆에 있는 앱 검색

사람 앱을 엽니다. 주석 및 패키지 매니페스트에서 지정한 각 작업 옆에 앱이 표시됩니다.

Contact Card

사용자가 작업용 앱을 선택하면 다음에 사용자가 연락처 카드 열 때 해당 작업의 기본 앱으로 표시됩니다.

미니 연락처 카드에서 작업 옆에 있는 앱 검색

미니 연락처 카드에서 작업을 나타내는 탭에 앱이 표시됩니다.

Mini Contact Card

메일 앱 같은 앱이 미니 연락처 카드를 엽니다. 앱도 이를 열 수 있습니다. 이 코드로 이 작업을 수행하는 방법을 알 수 있습니다.

public async void OpenContactCard(object sender, RoutedEventArgs e)
{
    // Get the selection rect of the button pressed to show contact card.
    FrameworkElement element = (FrameworkElement)sender;

    Windows.UI.Xaml.Media.GeneralTransform buttonTransform = element.TransformToVisual(null);
    Windows.Foundation.Point point = buttonTransform.TransformPoint(new Windows.Foundation.Point());
    Windows.Foundation.Rect rect =
        new Windows.Foundation.Rect(point, new Windows.Foundation.Size(element.ActualWidth, element.ActualHeight));

   // helper method to find a contact just for illustrative purposes.
    Contact contact = await findContact("contoso@contoso.com");

    ContactManager.ShowContactCard(contact, rect, Windows.UI.Popups.Placement.Default);

}

미니 연락처 카드 더 많은 예제를 보려면 연락처 카드 샘플을 참조하세요.

연락처 카드와 마찬가지로 각 탭은 앱으로 쉽게 돌아갈 수 있도록 사용자가 마지막으로 사용한 앱을 기억합니다.

사용자가 연락처 카드에서 앱을 선택할 때 작업 수행

App.cs 파일에서 Application.OnActivated 메서드를 재정의하고 사용자를 앱의 페이지로 이동합니다. 연락처 카드 통합 샘플에서 그렇게 하는 한 가지 방법을 보여줍니다.

페이지의 코드 숨김 파일에서 Page.OnNavigatedTo 메서드를 재정의합니다. 연락처 카드는 작업 이름 및 사용자의 ID를 이 메서드에 전달합니다.

비디오 또는 오디오 통화를 시작하는 방법은 VoIP 샘플을 참조하세요. WIndows.ApplicationModel.Calls 네임스페이스에서 전체 API를 찾을 수 있습니다.

메시징을 쉽게 하는 방법은 Windows.ApplicationModel.Chat 네임스페이스를 참조하세요.

다른 앱을 시작할 수도 있습니다. 이것이 이 코드가 수행하는 작업입니다.

protected override async void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);

    var args = e.Parameter as ProtocolActivatedEventArgs;
    // Display the result of the protocol activation if we got here as a result of being activated for a protocol.

    if (args != null)
    {
        var options = new Windows.System.LauncherOptions();
        options.DisplayApplicationPicker = true;

        options.TargetApplicationPackageFamilyName = "ContosoApp";

        string launchString = args.uri.Scheme + ":" + args.uri.Query;
        var launchUri = new Uri(launchString);
        await Windows.System.Launcher.LaunchUriAsync(launchUri, options);
    }
}

args.uri.scheme 속성에는 작업 이름이 포함되고 args.uri.Query 속성에는 사용자의 ID가 포함됩니다.