C# Xamarin使用参数进行表单应用程序链接

C# Xamarin使用参数进行表单应用程序链接,c#,xamarin,xamarin.forms,xamarin.android,xamarin.ios,C#,Xamarin,Xamarin.forms,Xamarin.android,Xamarin.ios,我有个问题。我想从我的php页面启动我的应用程序,并通过该链接传递一个变量。然后在我的应用程序站点上,我需要读取参数并使用该参数执行我想要的操作。现在我已经找到了这个链接:。这个人用Xamarin.Android来做这件事。但是如何在Xamarin.Forms中实现这一点,或者类似于此?我将使用以下url作为示例向您展示如何实现这一点: xamboy.com:与应用程序链接关联的域 你好:是应用程序链接路径 Rendy:参数 首先,您需要为每个平台配置app link支持。通过执行以下步骤:

我有个问题。我想从我的php页面启动我的应用程序,并通过该链接传递一个变量。然后在我的应用程序站点上,我需要读取参数并使用该参数执行我想要的操作。现在我已经找到了这个链接:。这个人用
Xamarin.Android
来做这件事。但是如何在
Xamarin.Forms
中实现这一点,或者类似于此?

我将使用以下url作为示例向您展示如何实现这一点:

  • xamboy.com:与应用程序链接关联的域
  • 你好:是应用程序链接路径
  • Rendy:参数
首先,您需要为每个平台配置app link支持。通过执行以下步骤:

苹果门户配置
  • 转到应用程序ID部分并单击应用程序
  • 在应用程序服务列表中,滚动至底部并单击编辑
  • 启用关联的域并保存
  • 网站配置 为了验证与应用程序的域关联,需要在网站中上载定义此关联的文件

    需要创建名为apple app site association的文件。此文件应包含以下json结构:

    {
        "applinks": {
            "apps": [],
            "details": [
                {
                    "appID": "CNAL8C4H5U.com.crossgeeks.applinkssample",
                    "paths": [ "/hello/*"]
                }
            ]
        }
    }
    
    [
       {
          "relation":[
             "delegate_permission/common.handle_all_urls"
          ],
          "target":{
             "namespace":"android_app",
             "package_name":"com.crossgeeks.applinkssample",
             "sha256_cert_fingerprints":[
                "3E:5D:E5:3B:BC:5A:61:BC:9E:96:34:C7:C2:D6:9F:BB:32:3C:8E:C5:FD:CE:D2:76:4C:81:98:2F:41:12:15:DD"
             ]
          }
       }
    ]
    
    例如:

    此文件应放在.well-known文件夹中或网站的根路径()

    • appID是前缀+(.)和ID的组合

    • 路径是应用程序将处理的所有路径(如果url上存在)的定义。例如,在我们的例子中,是因为我们刚刚在apple应用程序站点关联文件中将/hello定义为一个路径

    • apple应用程序站点关联文件不应具有文件扩展名
    安卓配置 需要创建名为assetlinks.json的数字资产文件。这里有一个在线工具可帮助您创建和测试此文件:

    它应该包含以下json结构:

    {
        "applinks": {
            "apps": [],
            "details": [
                {
                    "appID": "CNAL8C4H5U.com.crossgeeks.applinkssample",
                    "paths": [ "/hello/*"]
                }
            ]
        }
    }
    
    [
       {
          "relation":[
             "delegate_permission/common.handle_all_urls"
          ],
          "target":{
             "namespace":"android_app",
             "package_name":"com.crossgeeks.applinkssample",
             "sha256_cert_fingerprints":[
                "3E:5D:E5:3B:BC:5A:61:BC:9E:96:34:C7:C2:D6:9F:BB:32:3C:8E:C5:FD:CE:D2:76:4C:81:98:2F:41:12:15:DD"
             ]
          }
       }
    ]
    
    例如:

    此文件应放在网站()的.well-known文件夹中

    如果您想测试一切正常,可以使用以下url:

    https://:&relation=delegate\u permission/common.handle\u all\u URL

    如果一切正常,则应类似于此:

    在移动项目中配置应用程序链接 iOS项目 转到authentications.plist文件,启用属性关联域,并使用以下格式添加网站的域:yourdomain.com和applinks:*.yourdomain.com

    安卓项目 通过为每个要支持的域/路径/协议添加IntentFilter,在Android MainActivity上配置应用程序链接

    [活动(Label=“AppLinksSample”,Icon=“@mipmap/Icon”,Theme=“@style/MainTheme”,
    MainLauncher=true,
    ConfigurationChanges=ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    //邀请应用程序链接
    [IntentFilter(新[]{Android.Content.Intent.ActionView},
    DataScheme=“https”,
    DataHost=“xamboy.com”,
    DataPathPrefix=“/hello”,
    自动验证=真,
    Categories=new[]{Android.Content.Intent.CategoryDefault,Android.Content.Intent.CategoryBrowsable}]
    [IntentFilter(新[]{Android.Content.Intent.ActionView},
    DataScheme=“http”,
    DataHost=“xamboy.com”,
    自动验证=真,
    DataPathPrefix=“/hello”,
    Categories=new[]{Android.Content.Intent.CategoryDefault,Android.Content.Intent.CategoryBrowsable}]
    公共类MainActivity:全局::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
    创建时受保护的覆盖无效(Bundle savedInstanceState)
    {
    TabLayoutResource=Resource.Layout.Tabbar;
    ToolbarResource=Resource.Layout.Toolbar;
    base.OnCreate(savedInstanceState);
    全局::Xamarin.Forms.Forms.Init(这个,savedInstanceState);
    加载应用程序(新应用程序());
    }
    受保护的覆盖无效Wintent(意图)
    {
    基恩温特(意图);
    }
    }
    
    表格项目 在App.cs文件中,重写applinkRequestReceived的方法。在这里,您可以处理通过应用程序链接打开应用程序时发生的情况,并处理以下参数:

    applinkRequestReceived上受保护的覆盖无效(Uri)
    {
    if(uri.Host.EndsWith(“xamboy.com”,StringComparison.OrdinalIgnoreCase))
    {
    if(uri.Segments!=null&&uri.Segments.Length==3)
    {
    var action=uri.Segments[1]。替换(“/”,“”);
    var msg=uri.Segments[2];
    开关(动作)
    {
    案例“你好”:
    如果(!string.IsNullOrEmpty(msg)){
    Device.BeginInvokeMainThread(异步()=>
    {
    等待Current.MainPage.DisplayAlert(“hello”,msg.Replace(&),“”),“ok”);
    });
    }
    打破
    违约:
    Xamarin.Forms.Device.OpenUri(uri);
    打破
    }
    }
    }
    }
    

    由于我可以阅读页面,如果我的应用程序不在playstore中,我就不能使用深度链接。对吗?