應用程式間通訊App-to-app communication

本節說明如何在通用 Windows 平台 (UWP) 應用程式之間共用資料,包括如何使用分享協定、複製並貼上、拖放以及應用程式服務。This section explains how to share data between Universal Windows Platform (UWP) apps, including how to use the Share contract, copy and paste, drag and drop, and app services.

分享協定是一種使用者可以在 App 之間快速交換資料的方法。The Share contract is one way users can quickly exchange data between apps. 舉例來說,使用者可能會想要使用社交網路 app 與朋友分享網頁,或是將連結儲存在筆記本 app 以供日後參考。For example, a user might want to share a webpage with their friends using a social networking app, or save a link in a notes app to refer to later. 如果您 App 接收的內容是使用者可以在另一個 App 環境中快速完成的內容,請考慮使用分享協定。Consider using a Share contract if your app receives content in scenarios that a user can quickly complete while in the context of another app.

App 可以用兩種方式支援分享功能。An app can support the Share feature in two ways. 第一種,App 可以是來源 app,提供使用者要分享的內容First, it can be a source app that provides content that the user wants to share. 第二種,App 可以是目標 app,使用者選取做為分享內容的目的地Second, the app can be a target app that the user selects as the destination for shared content. App 可以既是來源 App 也是目標 App。An app can also be both a source app and a target app. 如果您希望將 App 當作來源 App 來分享內容,您需要決定 App 可以提供的資料格式。If you want your app to share content as a source app, you need to decide what data formats your app can provide.

除了分享協定之外,App 也可以整合傳統的資料來傳輸技術,例如拖放複製並貼上In addition to the Share contract, apps can also integrate classic techniques for transferring data, such as dragging and dropping or copy and pasting. 除了 UWP app 之間的通訊之外,這些方法也支援分享至傳統型應用程式及從傳統型應用程式分享。In addition to communication between UWP apps, these methods also support sharing to and from desktop applications.

UWP 應用程式也可以建立應用程式服務,以提供其他 UWP 應用程式的功能。UWP apps can also create app services that provide functionality to other UWP apps. 應用程式服務在主控 App 中以背景工作方式執行,並且可以將其服務提供給其他 App。An app service runs as a background task in the host app and can provide its service to other apps. 例如,應用程式服務可能會提供其他 App 可以使用的條碼掃描器服務。For example, an app service might provide a bar code scanner service that other apps could use.

本節內容In this section

主題Topic 描述Description
共用資料Share data 本文說明如何在 UWP app 中支援分享協定。This article explains how to support the Share contract in a UWP app. 分享協定是一種在 app 之間快速分享資料 (例如文字、連結,照片和影片) 的簡單方法。The Share contract is an easy way to quickly share data, such as text, links, photos, and videos, between apps. 舉例來說,使用者可能會想要使用社交網路 app 與朋友分享網頁,或是將連結儲存在筆記本 app 以供日後參考。For example, a user might want to share a webpage with their friends using a social networking app, or save a link in a notes app to refer to later.
接收資料Receive data 本文說明如何使用分享協定在您的 UWP app 中接收從另一個 app 分享的內容。This article explains how to receive content in your UWP app shared from another app using Share contract. 分享協定可以在使用者叫用分享時,讓您的應用程式成為一個選項。This Share contract allows your app to be presented as an option when the user invokes Share.
複製和貼上Copy and paste 本文說明如何使用剪貼簿在 UWP app 中支援複製和貼上。This article explains how to support copy and paste in UWP apps using the clipboard. 複製和貼上是在 App 間 (或是 App 內) 交換資料的傳統方式,而且幾乎每個 App 在某種程度上都能支援剪貼簿作業。Copy and paste is the classic way to exchange data either between apps, or within an app, and almost every app can support clipboard operations to some degree.
拖放功能Drag and drop 本文說明如何在您的 UWP app 中新增拖放功能。This article explains how to add dragging and dropping in your UWP app. 拖放是一種與影像和檔案之類的內容進行互動的傳統、原始方式。Drag and drop is a classic, natural way of interacting with content such as images and files. 實作之後,拖放不論以哪一個方向都能順暢運作,包括應用程式間、應用程式到傳統型應用程式,以及傳統型應用程式到應用程式。Once implemented, drag and drop works seamlessly in all directions, including app-to-app, app-to-desktop, and desktop-to app.
建立和使用應用程式服務Create and consume an app service 本文說明如何在 UWP 應用程式中建立應用程式服務,以提供服務給其他 UWP 應用程式。This article explains how to create an app service in a UWP app that provides services to other UWP apps.

另請參閱See also