Implemented deeplinking in android

This commit is contained in:
Tobias Reski 2021-11-19 10:35:26 +01:00
parent 950c50f218
commit d734d4e5e5
13 changed files with 12150 additions and 9637 deletions

View file

@ -191,6 +191,9 @@
<PackageReference Include="Xamarin.GooglePlayServices.Basement" Version="117.6.0.2" />
<PackageReference Include="Xamarin.GooglePlayServices.Maps" Version="117.0.1.1" />
<PackageReference Include="Xamarin.GooglePlayServices.Tasks" Version="117.2.1.1" />
<PackageReference Include="Xamarin.Forms.AppLinks">
<Version>5.0.0.2244</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Reference Include="Mono.Android" />

View file

@ -4,11 +4,28 @@ using Android.Content.PM;
using Android.OS;
using Android.Content;
using Java.Interop;
using Xamarin.Forms.Platform.Android.AppLinks;
using Firebase;
namespace TINK.Droid
{
[Activity (Label = "LastenradBayern", Icon = "@drawable/sharee", Theme="@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
[IntentFilter(new[] { Intent.ActionView },
Categories = new[] { Intent.ActionView, Intent.CategoryBrowsable, Intent.CategoryDefault },
DataScheme = "https",
DataHost = "sharee.bike", // TODO: Adjust to correct domain
DataPathPrefix = "/",
AutoVerify = true)]
[IntentFilter(new[] { Intent.ActionView },
Categories = new[] { Intent.ActionView, Intent.CategoryBrowsable, Intent.CategoryDefault },
DataScheme = "http",
DataHost = "sharee.bike", // TODO: Adjust to correct domain
DataPathPrefix = "/",
AutoVerify = true)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate (Bundle bundle)
{
@ -19,6 +36,9 @@ namespace TINK.Droid
global::Xamarin.Forms.Forms.Init (this, bundle);
FirebaseApp.InitializeApp(this);
AndroidAppLinks.Init(this);
// Initialize xamarin.essentials, see https://docs.microsoft.com/en-us/xamarin/essentials/get-started?tabs=macos%2Candroid.
Xamarin.Essentials.Platform.Init(this, bundle);

File diff suppressed because it is too large Load diff

View file

@ -254,6 +254,28 @@ namespace TINK
.CreateLogger();
}
/// <param name="uri">The URI for the request.</param>
/// <summary>Overriden to respond when the user initiates an app link request.</summary>
protected override void OnAppLinkRequestReceived(Uri uri)
{
base.OnAppLinkRequestReceived(uri);
// TODO: Adjust to correct host
if (uri.Host.ToLower() == "sharee.bike")
{
// Input e.g. sharee.bike/sharee/lastenrad/?lat=49.921&long=32.51
Array segments = Array.ConvertAll(uri.Segments, segment => segment.Replace("/", "")).Skip(1).ToArray();
Dictionary<string, string> queryDict = uri.Query
.Substring(1)
.Split("&")
.Select(query => query.Split('='))
.ToDictionary(query => query.FirstOrDefault(), query => query.Skip(1).FirstOrDefault());
// segments == ["sharee", "lastenrad"]
// queryDict == [{["lat", "49.921"]}], {["long", "32.51"]}]
// => Navigate and pass params depending on linkinput
// If no custom navigation is configured, the app just opens as if the user opened it
}
}
/// <summary> Gets the current logging level.</summary>
/// <returns></returns>
private static LogEventLevel GetCurrentLogEventLevel()