private async void CreateShortOrLongAppLink_Click(object sender, EventArgs e) { ShortAppLinking link = null; switch ((sender as Button).Id) { case Resource.Id.btnCreateLongAppLink: //Create Long Link FindViewById <TextView>(Resource.Id.txtLinkTitle).Text = "Long Link"; FindViewById <Button>(Resource.Id.btnConvert).Enabled = true; try { link = await builder.BuildAppShortLinkingAsync(ShortAppLinking.LENGTH.Long); SendResult(new Uri[] { link.ShortUrl, link.TestUrl }); longLink = link.ShortUrl; } catch (Exception ex) { Debug.WriteLine("Error: " + ex.ToString()); } break; case Resource.Id.btnCreateShortAppLink: //Create Short Link FindViewById <Button>(Resource.Id.btnConvert).Enabled = false; FindViewById <TextView>(Resource.Id.txtLinkTitle).Text = "Short Link"; try { link = await builder.BuildAppShortLinkingAsync(ShortAppLinking.LENGTH.Short); SendResult(new Uri[] { link.ShortUrl, link.TestUrl }); } catch (Exception ex) { Debug.WriteLine("Error: " + ex.ToString()); } break; default: break; } }
private async void CreateAppLinkAsync(object sender, EventArgs e) { string UriPrefix = "<your_AppLinking_URL_Prefix>"; string OpenDeep_Link = "https://developer.huawei.com"; string AndroidDeep_Link = "androidlink://developer.huawei.com/consumer/cn"; AppLinking.Builder builder = new AppLinking.Builder(); // Set URL Prefix builder.SetUriPrefix(UriPrefix); // Set Deep Link builder.SetDeepLink(Uri.Parse(OpenDeep_Link)); //Set the link preview type. If this method is not called, the preview page with app information is displayed by default. builder.SetPreviewType(AppLinking.LinkingPreviewType.AppInfo); // Set Android link behavior (Optional) // If this parameters not set, the link will be opened in the Android browser by default. var androidLinkInfo = new AppLinking.AndroidLinkInfo.Builder(); androidLinkInfo.SetAndroidDeepLink(AndroidDeep_Link); androidLinkInfo.SetOpenType(AppLinking.AndroidLinkInfo.AndroidOpenType.AppGallery); builder.SetAndroidLinkInfo(androidLinkInfo.Build()); // obtain the long link. FindViewById <TextView>(Resource.Id.longLinkText).Text = builder.BuildAppLinking().Uri.ToString(); // obtain the short link. try { ShortAppLinking link = await builder.BuildAppShortLinkingAsync(ShortAppLinking.LENGTH.Short); FindViewById <TextView>(Resource.Id.shortLinkText).Text = link.ShortUrl.ToString(); } catch (Exception ex) { Debug.WriteLine("Error: " + ex.ToString()); } }