聯絡人註解描述應用程式支援聯絡人的通訊動作,例如瀏覽個人檔案、傳送訊息或撥打電話。 本文說明如何宣告這些功能,以及 Windows 如何在你的應用程式中開啟相關聯絡人。
開始之前,請先將你的聯絡人新增到 Windows。
宣告支援的通訊作業
應用程式可以透過 SupportedOperations 屬性(位於 ContactAnnotation 上),宣告該聯絡人所支援的通訊能力。
此 SupportedOperations 屬性指定應用程式支援與聯絡人互動的通訊動作類型。 這些操作由 ContactAnnotationOperations 列舉定義。
由於 ContactAnnotationOperations 是旗標枚舉,可以使用二進位 OR(|)運算子組合多個旗標值。 這讓應用程式能在單一註解中標示該聯絡人所有支援的通訊功能。 欲了解更多此屬性資訊,請參閱 ContactAnnotation.SupportedOperations 的 API 參考資料。
以下範例說明如何宣告聯絡人所支援的通訊操作。
var annotation = new ContactAnnotation
{
ContactId = contact.Id,
RemoteId = contact.RemoteId,
SupportedOperations =
ContactAnnotationOperations.ContactProfile |
ContactAnnotationOperations.Message |
ContactAnnotationOperations.AudioCall |
ContactAnnotationOperations.VideoCall |
ContactAnnotationOperations.SocialFeeds
};
await this.contactAnnotationList.TrySaveAnnotationAsync(annotation);
在此範例中,註解向 Windows 宣告該應用程式支援查看聯絡人資料、發送訊息、進行音訊或視訊通話,以及存取指定聯絡人的社群動態更新。
應用程式應設定支援的操作,以準確反映該聯絡人在應用程式內可用的互動與通訊功能。
通訊啟動控制代碼
當使用者從 Windows 表面選擇通訊動作時,Windows 會使用註冊的 URI 協定啟動你的應用程式,並將聯絡人的 RemoteId 傳遞給應用程式。
以下的 URI 方案對應於 ContactAnnotationOperations 數值。
| Operation | URI 架構 |
SupportedOperations 旗標 |
|---|---|---|
| Call | ms-voip-call: |
AudioCall |
| 視訊 | ms-voip-video: |
VideoCall |
| 訊息 | ms-ipmessaging: |
Message |
| Profile | ms-contact-profile: |
ContactProfile |
例如,如果應用程式宣告AudioCall | VideoCall,Windows 可以使用如下 URI 來啟用該應用程式:
ms-voip-video:<RemoteId>
<RemoteId> 是你儲存在 ContactAnnotation 的相同 RemoteId 值。 利用它在你的應用程式中找到對應的使用者或對話,並啟動所要求的體驗。
只為你的應用程式支援的操作註冊 URI 方案。 Windows 只有在匹配協定註冊可用時才會顯示通訊動作。
註冊 URI 配置
將套件中的每個 URI 方案宣告為 windows.protocol 擴充功能。 以下範例登錄了用於檢視個人檔案、訊息傳遞、音訊通話及視訊通話的協定。
<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>