win10 uwp App-to-app communication 应用通信
来源:互联网 发布:javascript的面相对象 编辑:程序博客网 时间:2024/06/06 18:08
这篇文章都是乱说的,如果觉得有不好的,可以发我邮箱
应用之间需要相互的发送信息,就是我们经常用的分享
有个人看到一个网页很好,于是就希望把这个网页发送到邮件,那么这样的话就是使用应用通信。
因为每个应用都是不能访问其他应用数据,所以需要通信可以使用启动内置应用,文件关联应用。
发送数据
创建一个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
原文:https://msdn.microsoft.com/en-us/windows/uwp/app-to-app/index
- win10 uwp App-to-app communication 应用通信
- UWP win10 app 新关键字x:Bing
- Win10/UWP开发:让你的App使用上扫描仪
- win10 UWP 应用设置
- 卸载win10内置app应用
- [Discovery]初识Windows通用应用(UWP App) - HelloWorld
- Inter-App Communication
- Win10 UWP应用发布流程
- Win10/UWP开发—使用Cortana语音指令启动前台App
- Win10/UWP开发—使用Cortana语音与App后台Service交互
- Win10 UWP Intro to controls and events
- 【UWP开发】如何通过unity发布win10 uwp应用
- win10应用 UWP 使用MD5算法
- win10 uwp 装机必备应用 含源代码
- win10 uwp 应用转后台清理内存
- App应用间通信的一个方法
- android app to app
- UWP(1) 获取App 版本信息
- Unity5的关卡切换
- codevs 1017 乘积最大
- 一些可能还是碎片化的知识和认识
- ECMAScript 2015 (ES6) in Node.js(译)
- php strtotime 时间加减函数
- win10 uwp App-to-app communication 应用通信
- “代理服务器拒绝连接“问题
- Java网络编程之JavaMail发送邮件和接受邮件
- 存储过程(一)后台使用jdbc集成
- OA项目实战学习(1)
- hdu 2594 Simpsons’ Hidden Talents
- 20-30岁,你拿这十年做什么(读书摘录)
- UDP封装基础学习记录
- 存储过程(二) 逻辑判断