Xamarin-铆钉组件-应用程序未启动时的DeepLink



我正在使用Xamarin铆钉组件创建一个深度链接的android应用程序。当我在后台运行应用程序时,我可以深度链接到应用程序。然而,当应用程序没有启动时,它会抛出异常。

我的代码来源于铆钉样本(https://components.xamarin.com/gettingstarted/rivets)我的代码如下:

[Activity (Label = "ProductActivity")]
    [IntentFilter(new [] {Android.Content.Intent.ActionView },
        DataScheme= "mobisaveqaapp", //new[] {"mobisaveqaapp","mobisavedev"},
        DataHost="*",
        Categories=new [] { Android.Content.Intent.CategoryDefault })]
    public class ProductActivity : Activity
    {
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);
            SetContentView (Resource.Layout.ProductLayout);
            var id = "No Product ID Found";
            if (Intent.HasExtra ("al_applink_data")) {
                var appLinkData = Intent.GetStringExtra ("al_applink_data");
                var alUrl = new Rivets.AppLinkUrl (Intent.Data.ToString (), appLinkData);
                /*Todo: fetch Applinkdata target url,
                 * replace double slash with single slash,
                 * find the word offers,
                 * fecth the next index,
                 * start main activity,
                 * open all deals,
                 * open deal push async*/

                var offersVM = new OfferViewModel();
                var tableItems = offersVM.OfferCategories;
                Deal Localdeal = new Deal();
                foreach (var categories in tableItems)
                    if (categories.Key == "All Offers") {
                        Localdeal.DealName = categories.Key;
                        Localdeal.DealCount = categories.Value;
                        break;
                    }
                var url ="http://test:7070/nvtest/offers/664"; 
                url = url.Replace (":", "/");
                url = url.Replace ("//", "/");
                string[] words = url.Split('/');
                for(int i = 0;i<words.Length;i++) {
                    if (words [i].Trim ().ToLower () == "offers" && words [i + 1] != null) {
                        id = words [i + 1];
                        Device.BeginInvokeOnMainThread(() => {
                            if(App.Current != null && App.Current.MainPage != null && App.Current.MainPage.Navigation != null && App.Current.MainPage.Navigation.ModalStack.ToList ().Count > 0)
                            {
                                App.Current.MainPage.Navigation.PushModalAsync(new OffersSlideView(Localdeal, Convert.ToInt32(id)),false);  
                            }
                            else
                            {
                                App.Current.MainPage = new NavigationPage(new RootPageNew());
                            }
                        });
                    }
                }
            }
            this.Finish();

        }
    }

我需要关于如何启动深度链接应用程序的帮助。如果我哪里错了,或者这个问题不清楚,请告诉我。

您需要覆盖MainActivity.cs:上的OnSavedInstance

protected override void OnSaveInstanceState(Bundle outState)
{
   //Yes, comment or delete the next line:
   //base.OnSaveInstanceState(outState);
}

最新更新