アプリを連絡先カードの操作に接続する
アプリは、連絡先カードまたはミニ連絡先カードの操作の横に表示できます。 ユーザーは、プロファイル ページを開く、通話を行う、メッセージを送信するなど、操作を実行するアプリを選ぶことができます。
最初に、既存の連絡先を検索するか、新しい連絡先を作成します。 次に、注釈といくつかのパッケージ マニフェスト エントリを作成して、アプリがサポートする操作について説明します。 その後、操作を実行するコードを記述します。
完全なサンプルについては、連絡先カードの統合のサンプルをご覧ください。
連絡先を検索または作成する
他のユーザーとつながるのをサポートするアプリの場合、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 のマニフェスト デザイナーの [宣言] タブで追加することもできます。
連絡先カードの操作の横にあるアプリを見つける
People アプリを開きます。 アプリは、注釈とパッケージ マニフェストで指定した各操作の横に表示されます。
ユーザーが操作のためにアプリを選ぶと、次回ユーザーが連絡先カードを開いたときに、そのアプリがその操作用の既定のアプリとして表示されます。
ミニ連絡先カードの操作の横にあるアプリを見つける
ミニ連絡先カードでは、操作を表すタブにアプリが表示されます。
ミニ連絡先カードは、メール アプリなどのアプリで開くことができます。 お使いのアプリでミニ連絡先カードを開くこともできます。 次のコードは、その方法を示しています。
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 メソッドをオーバーライドし、ユーザーをアプリ内のページに移動させます。 それを行う方法の 1 つについては、連絡先カードの統合のサンプルをご覧ください。
ページのコード ビハインド ファイルで、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 が含まれています。
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示