如何在调用另一个Windows-Phone应用程序时传递数据? [英] How to pass data when calling another Windows-Phone App?

查看:72
本文介绍了如何在调用另一个Windows-Phone应用程序时传递数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我开始在WP开发中,但我已经遇到以下情况。我有我的应用程序,我需要其他应用程序来调用它传递我将指定的数据/参数。例如:App X将调用并打开我的应用程序,传递id,name和age等参数。 I
查找了一些答案,但只找到了3年前提出的问题。

I am starting in WP development but I already got the following situation. I have my app and I need other apps to call it passing data/parameters that I will specify. For example: App X will call and open my app, passing parameters like id, name and age. I looked up for some answers but only found questions made 3 years ago.


现在有办法吗?谢谢。

Is there any way to do it now? Thanks.

推荐答案

lucianognr

Hi, lucianognr

激活其他应用时可以传递数据。有几种方法可以做到这一点。

It's possible to pass data when activating other apps. There are several ways you can do that.

1。文件类型 关联

首先在您的应用中,在声明选项卡的Package.appxmanifest中声明文件类型关联

First in your app, declare a File Type Association in the Package.appxmanifest in the Declarations tab.

例如

<uap:Extension Category="windows.fileTypeAssociation">
    <uap:FileTypeAssociation Name="test">
        <uap:SupportedFileTypes>
            <uap:FileType>.myapptest</uap:FileType>
        </uap:SupportedFileTypes>
    </uap:FileTypeAssociation>
</uap:Extension>

这意味着您的应用可以使用扩展名.myapptest处理一些文件。

This means your app can handle some files with extension .myapptest.

其次,在App X中,它应该创建一个扩展名为.myapptest的文件,其中包含任何内容,例如id,name和age。然后使用
Windows.System.Launcher打开此文件。

Secondly, in App X, it should create a file with extension .myapptest putting any content in it, like id, name and age. And then use Windows.System.Launcher to open this file.

第三,当打开.myapptest文件时,您的应用将通过覆盖方法激活  OnFileActivated 在App.cs中使用
FileActivatedEventArgs pamameter。然后在您的应用中,阅读FileActivatedEventArgs的
文件 属性。所以你可以得到你的身份,姓名和年龄。

Thirdly, when a .myapptest file is opened, your app will be activated via the override method OnFileActivated in App.cs with an FileActivatedEventArgs pamameter. Then in your app, read the Files property of FileActivatedEventArgs. So you can get your id, name and age.

2。协议关联

协议关联比文件类型关联容易得多。

Protocol association is much easier than File Type Associate.

与上述相同,首先在Package.appxmanifest中声明协议

Same as above, first declare a Protocol in Package.appxmanifest.

例如

<Extensions>
    <uap:Extension Category="windows.protocol">
        <uap:Protocol Name="myapptest" />
    </uap:Extension>
</Extensions>

其次,在App X中,通过

Secondly, in App X, call your app via

await Windows.System.Launcher.LauncherUriAsync(new Uri("myapptest://id=0&name=test&age=10"));

第三,在你的应用中,覆盖方法App.cs中的 OnActivated 将被调用。它将携带一个pameter
IActivatedEventArgs Kind == ActivationKind.Protocol。
然后将其转换为 ProtocolActivatedEventArgs类型,以便您 获取
Uri 此参数中的属性。接下来只需解析Uri并得到你想要的东西。

Thirdly, in your app, an override method OnActivated in App.cs will be invoked. It will carry a pameter IActivatedEventArgs with Kind == ActivationKind.Protocol. And then just cast it into ProtocolActivatedEventArgs type so that you can get the Uri property in this parameter. Next just parse the Uri and get what you want.

最好的问候。


这篇关于如何在调用另一个Windows-Phone应用程序时传递数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆