Windows Phone 8/Windows 8 启动第三方应用程序并传递参数
需要被其他应用启动的第三方应用需要注册protocol association,当一个应用程序启动一个特殊的URI的时候,那么注册了这个protocol的程序会自动启动,并且可以通过这个特殊的URI将参数传递到第三方应用中。
第三方应用程序注册protocol association步骤
Windows Phone 8 和 Windows 8 注册方式有一些差异,下面分别说明注册方式。
Windows Phone 8第三方应用程序注册Protocol
1.修改WPAppManifest.xaml文件
在</Token>后面添加类似如下代码:
<Extensions>
<Protocol Name="testapp" NavUriFragment="encodedLaunchUri=%s" TaskID="_default"/>
</Extensions>
MSDN关于Protocol标签的说明参考:Windows Phone 的应用清单文件
Protocol 元素是 Extensions 元素的子元素,始终应该跟在所有 FileTypeAssociation 元素后面。Protocol 元素说明了应用注册的 URI 方案名称,使其可以在另一个应用启动某个特定 URI 时启动。有关更多信息,请参见 使用 Windows Phone 8 文件和 URI 关联的自动启动应用。
|
属性 |
类型 |
说明 |
|
Name |
String |
自定义的 URI 方案的前缀。包含数字、小写字母、句点 (‘.’) 或连字符 (‘-’) 且长度介于 2 和 39 个字符的字符串。不包含冒号 (‘:’)或任何在 URI 中的前缀后面的内容。 |
|
NavUriFragment |
String |
始终设置为 encodedLaunchUri=%s。 |
|
TaskID |
String |
始终设置为 _default。 |
2.添加URI请求解析处理程序
传人程序的UIR格式为:/Protocol?encodedLaunchUri={传人的URI},为了使程序能够正确解析传人的URI,需要为工程添加AssociationUriMapper类,代码如下:
/// <summary>
/// 解析第三方应用调用参数
/// </summary>
class AssociationUriMapper : UriMapperBase
{
private string tempUri; public override Uri MapUri(Uri uri)
{
tempUri = uri.ToString(); // Protocol association launch for contoso.
if (tempUri.Contains("/Protocol"))
{
int pos = tempUri.IndexOf("encodedLaunchUri");
String encodedString = tempUri;
if (pos >= )
{
encodedString = tempUri.Substring(pos);
}
return new Uri("/MainPage.xaml?" + encodedString, UriKind.Relative);
} // Include the original URI with the mapping to the main page.
return new Uri("/MainPage.xaml", UriKind.Relative);
}
}
3.修改App.xaml.cs文件的InitializePhoneApplication,添加:
// Assign the URI-mapper class to the application frame.
RootFrame.UriMapper = new AssociationUriMapper();
4.修改MainPage.xaml.cs文件,添加提示框,弹出传人的URI,代码如下:
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
//解析第三方应用调用参数
if (NavigationContext.QueryString.ContainsKey("encodedLaunchUri"))
{
String launchuri = NavigationContext.QueryString["encodedLaunchUri"];
MessageBox.Show(launchuri);
//launchuri为传人的URI,解析并保存传人的参数
//-----TO DO--------------
}
}
Windows 8第三方应用程序注册Protocol
1.修改Package.appxmanifest文件
找到<Application>标签的子标签<Extensions>,如果不存在,则添加一个。为<Extensions>添加子标签:
<Extension Category="windows.protocol">
<Protocol Name="testapp" />
</Extension>
2.修改App.xaml.cs文件,添加如下代码
protected override void OnActivated(IActivatedEventArgs args)
{
base.OnActivated(args); //第三方应用调用处理
if (args.Kind == ActivationKind.Protocol)
{
var protocolArgs = args as ProtocolActivatedEventArgs;
String uristring = protocolArgs.Uri.AbsoluteUri;
//uristring为传人的URI,解析并保存传人的参数
//-----TO DO--------------
}
Window.Current.Activate();
}
第三方应用调用方式
Windows Phone 8 和 Windows 8 调用方式相同,格式为:testapp:xxxxxxxxx,其中:testapp为注册Protocol的name。实例代码如下:
Windows.System.Launcher.LaunchUriAsync(new Uri("testapp://type/?param1=value1¶m2=value2¶m3=value3 "));
Windows Phone 8/Windows 8 启动第三方应用程序并传递参数的更多相关文章
- 如何在Android中的Activity启动第三方应用程序?
如何在点击某个按键后,执行启动第三方应用程序界面? /** * <功能描述> 启动应用程序 * * @return void [返回类型说明] */ private void startU ...
- Android启动第三方应用程序
主要是开始通过包名的第三方应用程序,获取的方法的包名是非常在线.不是说. 两种方式启动: 第一: Intent intent = new Intent(); intent.setClassName(& ...
- Android: 启动另外的APP及传递参数(转)
转载自:http://blog.csdn.net/iefreer/article/details/8812585 有时候需要从一个APP中启动另外一个APP,比如Twitter/微信等. 如果你不知道 ...
- Windows server 2008 R2 如何启动任务计划程序
使用windows server 2008 R2 的任务计划程序需要启动服务 Task Scheduler 服务, windows server 2008 R2 默认状态下Task Schedule ...
- 安卓入门 使用android创建一个项目 从启动activity中响应按钮事件 启动另一个activity 并传递参数
启动android studio创建一个新项目 public void sendMessage(View view){ Intent intent=new Intent(this,DispalyMes ...
- 【WP8】Uri关联启动第三方App
在WP8中支持启动第三方应用程序,比如在App1中可以打开App2,你可以在你的应用程序中直接打开QQ,也可以让其他开发者调用你的APP,例如:软件盒子 下面演示被调用方和调用方的使用方法,新建两个项 ...
- Windows 2003 Server 标准版启动问题解决(资源转贴)
维护的系统之一是部署在windows2003 Server标准版的服务器上,可能是由于某个应用问题,导致远程重启失败,害得我在机房呆了一早晨,可算是够折腾的.最后按照官方文档解决,刚放文档地址是:ht ...
- windows下postgreSQL安装与启动
转:https://www.yiibai.com/postgresql/install-postgresql.html https://blog.csdn.net/irainreally/articl ...
- 玩转Windows服务系列——Windows服务启动超时时间
最近有客户反映,机房出现断电情况,服务器的系统重新启动后,数据库服务自启动失败.第一次遇到这种情况,为了查看是不是断电情况导致数据库文件损坏,从客户的服务器拿到数据库的日志,进行分析. 数据库工作机制 ...
随机推荐
- python 内存问题(glibc库的malloc相关)
题记: 这是工作以来困扰我最久的问题.python 进程内存占用问题. 经过长时间断断续续的研究,终于有了一些结果. 项目(IM服务器)中是以C做底层驱动python代码,主要是用C完成 网络交互部分 ...
- 开放接口/RESTful/Api服务的设计和安全方案
总体思路 这个涉及到两个方面问题:一个是接口访问认证问题,主要解决谁可以使用接口(用户登录验证.来路验证)一个是数据数据传输安全,主要解决接口数据被监听(HTTPS安全传输.敏感内容加密.数字签名) ...
- linux 进程信号集合 sigset_t
sigset_t 号集及信号集操作函数:信号集被定义为一种数据类型: typedef struct { unsigned long sig[_NSIG_WORDS]: } sigset_t 信号集用来 ...
- HDU--1010
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 分析:dfs+奇偶剪枝. Tempter of the Bone #include<c ...
- linux中使用随机数
(1)单纯使用rand重复调用n次,就会得到一个0-RAND_MAX之间的伪随机数,如果需要调整范围,可以得到随机数序列后再进行计算.(2)单纯使用rand来得到伪随机数序列有缺陷,每次执行程序得到的 ...
- spring整合hibernate时报错:org.hibernte.engine.transaction.spi.transactioncontext
错误提示:Caused by:java.lang.ClassNotFoundException: org.hibernte.engine.transaction.spi.transactioncont ...
- 为VSCODE添加右键菜单
参考:https://blog.csdn.net/GreekMrzzJ/article/details/82194913 1.创建一个名为vscode.reg的空文本文件,填入下列内容 Windows ...
- hdu 4055 Number String
Number String http://acm.hdu.edu.cn/showproblem.php?pid=4055 Time Limit: 10000/5000 MS (Java/Others) ...
- HDP安全之集成kerberos/LDAP、ranger(knox自带LDAP)
----------------------目录导航见左上角------------------------------- 环境 HDP 3.0.1.0 (已有) JDK 1.8.0_91 (已有 ...
- k8s+docker学习连接汇总
http://guide.daocloud.io/dcs/docker-9153982.html http://www.dczou.com/viemall/802.html https://wangl ...