使用 Windows Phone 8 文件和 URI 关联的自动启动应用

更详细,猛撸这里:http://msdn.microsoft.com/zh-cn/library/windowsphone/develop/jj206987(v=vs.105).aspx

在WMAppManifest.xml清单文件加入,在Tokens节点后面加

 <Extensions>
      <Protocol Name="testuri" NavUriFragment="encodedLaunchUri=%s" TaskID="_default" />
  </Extensions>

修改Name的值为您为软件制定的协议名称

Protocol 元素由以下特性组成。

 

特性

说明

名称

自定义的 URI 方案的前缀。包含数字、小写字母、句点 (‘.’) 或连字符 (‘-’) 且长度介于 2 和 39 个字符的字符串。它不包含冒号 (‘:’)或任何紧跟其后的 URI 中的内容。

NavUriFragment

必须始终等于 encodedLaunchUri=%s

TaskID

必须始终等于 _default

注意:协议name 必须小写,大写会报错。。。。

第二部,增加一个类AssociationUriMapper

说明:这个类的内容只是一个案例,仅仅是简单启动应用,如果希望提供更能多特殊功能,可以根据自己的需求在这个类里做一些处理,可以根据不同的参数跳转到不同的应用程序页面

    public class AssociationUriMapper : UriMapperBase
    {
        private string tempUri;

        public override Uri MapUri(Uri uri)
        {
            tempUri = System.Net.HttpUtility.UrlDecode(uri.ToString());
            // URI association launch for testuri.
            //这里是协议名字,加上冒号
            if (tempUri.Contains("testuri:"))
            {
                // Map the show products request to MainPage.xaml
                return new Uri("/MainPage.xaml", UriKind.Relative);
            }

            // Otherwise perform normal launch.
            return uri;
        }
 
}
第三步:在App文件加入代码
   //注册协议
    RootFrame.UriMapper = new AssociationUriMapper();
 
 
 
 

第四步,新建一个项目 拖一个按钮 测试效果 button click事件加入以下代码

// Launch URI.

Windows.System.Launcher.LaunchUriAsync(new System.Uri("testuri:"));

 

如果你觉得还是不太明白,猛戳源码下载只支持wp8,环境:vs2012、 win8系统

http://files.cnblogs.com/walleyekneel/UriOpen.rar

刚睡醒,吃饭去....

 

原文地址:https://www.cnblogs.com/walleyekneel/p/3265084.html