這篇文章都是亂說的,如果覺得有不好的,可以發我郵箱?
應用之間需要相互的發送信息,就是我們經常用的分享?
?
有個人看到一個網頁很好,于是就希望把這個網頁發送到郵件,那么這樣的話就是使用應用通信。?
因為每個應用都是不能訪問其他應用數據,所以需要通信可以使用啟動內置應用,文件關聯應用。
## 發送數據
創建一個event 可以在用戶發送,共享發送
~~~
DataTransferManager data_transfer_manager = DataTransferManager.GetForCurrentView();
data_transfer_manager.DataRequested += DataTransferManager_DataRequested;
~~~
當DataRequested,應用收到一個DataRequest,這個是DataPackage可以在里面寫你要發送的信息。DataPackage必須寫標題和數據,如果有描述也寫
~~~
private static void DataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
DataRequest request = args.Request;
}
~~~
可以共享數據:
* 純文本
* url
* HTML
* 文本
* 圖片
* 文件
* 自己弄的我也不知道是什么的可以共享的
~~~
//文本
request.Data.SetText(text);
//uri
//request.Data.SetUri(uri);過時
request.Data.SetWebLink(uri);
//html
request.Data.SetHtmlFormat(html);
request.Data.SetRtf(text);
//文件
request.Data.SetStorageItems(file);
//圖片
request.Data.SetBitmap(bitmap);
~~~
我們需要和用戶說我們在做的數據
~~~
request.Data.Properties.Title = "標題";
request.Data.Properties.Description = "我的博客blog.csdn.net/lindexi_gd";
~~~
?
開始通信
~~~
DataTransferManager.ShowShareUI();
~~~
有時候我們需要等待一些操作需要時間,不能馬上就分享,我們可以使用
~~~
request.Data.Properties.Title = "標題";
request.Data.Properties.Description = "我的博客blog.csdn.net/lindexi_gd";
request.Data.SetDataProvider(StandardDataFormats.Bitmap, (data_provider_request) =>
{
DataProviderDeferral deferral = data_provider_request.GetDeferral();
//做時間比較長的操作
//一般可以把操作內容放try,因為操作內容主要是io,有出錯
//如果放在try,把deferral.Complete();finally
//try
//{
// //操作
//}
//finally
//{
// //deferral.Complete();
//}
deferral.Complete();
});
~~~
要接受其他的app我們需要設置`requestData.Properties.ContentSourceApplicationLink = ApplicationLink;`?
ApplicationLink是`new Uri("ms-sdk-sharesourcecs:navigate?page=" + 頁面名);`?
要接受其他的app我們需要設置?

?
我們在說明寫:林德熙博客?
但說明其實沒有什么用,主要是數據格式才是需要我們選擇,在上也看到我們可以分享的數據有多種格式,那么滿足格式的分享就會在分享看到我們的應用。?
?
新建一個頁面接分享,因為我想不到這個叫什么,我就放在MainPage?
導航到MainPage就是分享打開?
頁面傳參數可以使用,`Frame frame.Navigate`(頁面,參數)
~~~
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
~~~
在App.xaml.cs
~~~
protected override void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame=new Frame();
Window.Current.Content = rootFrame;//http://blog.csdn.net/lindexi_gd
}
rootFrame.Navigate(typeof (MainPage), args.ShareOperation);
Window.Current.Activate();
}
~~~
我們可以在OnNavigatedTo拿分享
~~~
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
ShareOperation share_operation = e.Parameter as ShareOperation;
if (share_operation == null)
{
return;
}
//標題
string shared_data_title = share_operation.Data.Properties.Title;
string shared_data_description = share_operation.Data.Properties.Description;
Uri url = share_operation.Data.Properties.ContentSourceWebLink;
Uri application_link = share_operation.Data.Properties.ContentSourceApplicationLink;
//圖像
RandomAccessStreamReference thumbnail = share_operation.Data.Properties.Thumbnail;
//應用名稱
string application_name = share_operation.Data.Properties.ApplicationName;
//數據
//判斷存在,如果不存在我們
if (share_operation.Data.Contains(StandardDataFormats.WebLink))
{
Uri web_link =await share_operation.Data.GetWebLinkAsync();
}
}
~~~
當我們做完可以告訴`share_operation.ReportCompleted();`?
如果錯了可以告訴發送我們接受錯?
分享成功經常返回一個鏈接,我們把一個東西分享到百度云,那么我們可以拿到一個鏈接百度云,可以發送,這個`QuickLink`
`QuickLink`·我們需要標題,圖標,id
~~~
QuickLink quickLinkInfo = new QuickLink()
{
Id = QuickLinkId,
Title = QuickLinkTitle,
SupportedFileTypes = { "*" },
SupportedDataFormats =
{
StandardDataFormats.Text,
StandardDataFormats.WebLink,
StandardDataFormats.ApplicationLink,
StandardDataFormats.Bitmap,//http://blog.csdn.net/lindexi_gd
StandardDataFormats.StorageItems,
StandardDataFormats.Html
},
Thumbnail = thumbnail,
};
share_operation.ReportCompleted(quickLinkInfo);
~~~
## 文件啟動
我們需要關聯?

在app.xaml.cs
~~~
protected override void OnFileActivated(FileActivatedEventArgs args)
{
// args.Files
}
~~~
Files包含文件可以拿來
博客:[http://blog.csdn.net/lindexi_gd](http://blog.csdn.net/lindexi_gd)
原文:[https://msdn.microsoft.com/en-us/windows/uwp/app-to-app/index](https://msdn.microsoft.com/en-us/windows/uwp/app-to-app/index)
- 前言
- UWP win10 app 新關鍵字x:Bing
- win10應用 UWP 使用MD5算法
- win10 UWP讀寫文件
- UWP appButtonBar樣式
- C# 6.0 $"Hello {csdn}"
- Win10 UWP xaml 延遲加載元素
- UWP xaml 圓形頭像
- UWP 繪制圖形
- win10 uwp 通知Toast
- win10 UWP 顯示地圖
- win10 uwp 參考
- win10 uwp clone
- win10 uwp 裝機必備應用 含源代碼
- RichEditBox 使用自定義菜單
- win10 UWP FlipView
- win10 UWP 獲取系統信息
- win10 UWP 申請微軟開發者
- win10 UWP button
- win10 UWP Markdown 含源代碼
- win10 UWP 應用設置
- win10 UWP 九幽數據分析
- win10 UWP 圓形等待
- win10 UWP 標題欄后退
- win10 UWP 單元測試
- win10 UWP 你寫我讀
- win10 UWP RSS閱讀器
- win10 UWP MessageDialog 和 ContentDialog
- win10 UWP Hmac
- win10 UWP GET Post
- Win10 UWP Intro to controls and events
- win10 UWP Controls by function
- win10 uwp App-to-app communication 應用通信