Xamarin.forms OnAppLinkRequestReceived - xamarin

I'm trying to use https://developer.xamarin.com/api/member/Xamarin.Forms.Application.OnAppLinkRequestReceived/p/System.Uri/ but can't seem to get it to be called in any way.
Did anyone ever tried to implement this new method?
I've tried several ways to implement different deeplinks, all of them open the app fine so they're correctly configured but that method never gets called.
Thanks.

This is how I set it up in Android.
Put this above your MainActivity.cs
[IntentFilter(new[] { Android.Content.Intent.ActionView },
Categories = new[]
{
Android.Content.Intent.CategoryDefault,
Android.Content.Intent.CategoryBrowsable
},
DataScheme = "http",
DataPathPrefix = "/tesla/",
DataHost = "exrin.net")]
This registers the activity when the app is installed. Change the URL to your desired URL.
For Android only (no need to do this with iOS) you need to also install the Nuget Xamarin Forms AppLinks
In your OnCreate make sure you do this after your Xamarin Forms Init
AndroidAppLinks.Init(this);
Then when you load the URL in a browser (in my example http://exrin.net/tesla) you will get this:
Then if you open the app it will enter here with the full URL as the URI parameter. This is in the App.cs (Xamarin.Forms.Application)
protected override void OnAppLinkRequestReceived(Uri uri)
{
base.OnAppLinkRequestReceived(uri);
}
You can then decode the URI as you see fit to move to the specific page in your app that the URL relates to/
More details at Xamarin Forms AppLinks

Also, your MainActivity must be derived from FormsAppCompatActivity for it to work. Once I changed it to that from FormsApplicationActivity, it started working.

Related

Forgot password workflow in Xamarin forms [duplicate]

Guys, I need to implement Applink (Universal Link) step by step both android and iOS, please any to help achieve this. I tried the following code in my android project
I followed this URL to write this https://devblogs.microsoft.com/xamarin/connect-with-your-users-with-google-search-and-app-indexing/
Note I no need to indexing concept just want to open the app from Clicking of any URL
First I Installed Xamarin.Forms.AppLinks NuGet
Below code MainActivity
[IntentFilter(new[] { Android.Content.Intent.ActionView },
Categories = new[]
{
Android.Content.Intent.CategoryDefault,
Android.Content.Intent.CategoryBrowsable
},
DataScheme = "http",
DataPathPrefix = "/",
DataHost = "test.com")]
Then write bellow code in OnCreate Method
AndroidAppLinks.Init(this);
Then I try to call deeplink URL "test://DeeplinkingSample" from Deep Link Tester
Its saying No Activity found to handle the intent
4.Then I try to call deeplink url "test://DeeplinkingSample" from Deep Link Tester
Its saying No Activity found to handle intent
You are trying to call the URL test://DeeplinkSample, which has the following parts
Scheme is test
Host is DeeplinkSample
No data path
However, you did not register your activity for that URL, but for the scheme http, with the host test.com and the data path prefix / (i.e. presumably all data paths that start with /). Hence the app should open when you are trying to open
http://test.com/...

Xamarin Forms Deep Linking

I have tried getting Xamarin Forms deep linking to work by following the example in https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/deep-linking.
It tells me I must have a version of my app live on Google Play, and I must also have a companion website registered with Google.
How am I supposed to test, develop, and debug my app if it has to already be published for this to work?
Note that I don't want app indexing, I just want deep linking. This all seems a bit involved - why do I even need a website?
All I basically want to do is authenticate the user to Strava via OAuth and handle the redirect URI.
Is there a simple example of how to get just deep linking to work, in such a way as it could handle the redirect URI from Strava?
I seem to have discovered a solution that works which is to simply put an IntentFilter on the MainActivity of my app:
[IntentFilter(
new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataSchemes = new[] { "<my package name>" },
DataHosts = new[] { "redirect.authorize.strava.<my package name>" }
)]
When I do this, it successfully calls OnAppLinkRequestReceived when strava fires the redirect URL with the deep link.
Wouldn't have known that from any docs though....

Open Native iOS app from Xamarin.Forms

I have an native iOS sample app installed in my iPad and also my sample xamarin.Forms App installed. I want to open native iOS app from Xamarin.forms when clicked on button. I have set URL schema in my native iOS app in info.plist.
How do I open native app from xamarin.forms on click of a button. I already tried
var request = Device.OnPlatform(
string.Format("native app url"),
string.Format("native app url"),
string.Format("native app url"));
Device.OpenUri(new Uri(request));
but its not working.
It's basically how you are doing it.
var url = Device.OnPlatform(iOSUrl, androidUrl, winPhoneUrl);
Device.OpenUri(new Uri(request));
Be aware that each platform have some requirements in the way to url is configured and parameters are sent.
Let say to get the maps app open in each platform you would use these urls schemes:
// iOS doesn't like %s or spaces in their URLs, so manually replace spaces with +s
var iOSUrl = string.Format("http://maps.apple.com/maps?q={0}&sll={1}", name.Replace(' ', '+'), loc);
var androidUrl = string.Format("geo:0,0?q={0}({1})", string.IsNullOrWhiteSpace(addr) ? loc : addr, name);
var winPhoneUrl = $"bingmaps:?cp={loc}&q={name}";
var url = Device.OnPlatform(iOSUrl, androidUrl, winPhoneUrl);
Also you cannot open any arbitrary app unless you know its Url scheme.
Anyway, if the Device.OpenUri() doesn't fulfill your requirements you are good to create your own implementations using the native APIs.
Please go through the below link and attached photo
Link:-launch-an-app-from-within-another-iphone
I am using below code in xamarin forms
NSUrl request = new NSUrl("Camera://");
var canOpen = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(request.ToString()));
if (!canOpen)
{ Task.FromResult(false); }
else
{
Task.FromResult(UIApplication.SharedApplication.OpenUrl(new NSUrl(request.ToString())));
}

Xamarin Forms' WebView - local assets not found on Windows Phone

I'm using WebView to display HTML from a string. This HTML references a stylesheet that I have locally on the device. I'm following the instructions from the official docs so the local CSS file can be accessed. It works fine on Android and iOS but I can't make it work on Windows Phone 8.1. I placed the CSS file in the root of the project and set the build action to Content, then set the BaseUrl to "" (I tried ms-appx-web:/// as well, with no success).
Does anyone know if the docs are missing some instructions? Or is it a bug in Forms? Any help would be appreciated.
Here's the code for populating the WebView with data (in a Forms PCL):
private async Task LoadData()
{
string html = await _dataProvider.GetHtmlAsync("index");
WebView.Source = new HtmlWebViewSource
{
Html = html,
BaseUrl = _baseUrlProvider.Get()
};
}
_baseUrlProvider is an instance of my WebViewBaseUrlProvider that is defined as follows:
internal class WebViewBaseUrlProvider : IWebViewBaseUrlProvider
{
public string Get() => "";
}
EDIT:
Seeing this question leads me to believe that there indeed is a bug in Xamarin Forms. When the link in the HTML contains the whole ms-appx-web:///style.css instead of just style.css, it suddenly starts to work. Obviously, this is not quite cross-platform...
I just found the answer - Xamarin simply ignores the BaseUrl property: https://github.com/xamarin/Xamarin.Forms/blob/2d9288eee6e6f197364a64308183725e7bd561f9/Xamarin.Forms.Platform.WinRT/WebViewRenderer.cs#L26

Windows Phone: Navigate between apps

I have an app that needs to include a links to a second app in the same phone.
If the app is not installed the link should point to the windows store to install it (that part is working fine).
But if the app is already installed the link should go straight to the app and open it. How can I do that?
The app has two versions one form WP7 and other from WP8. if the solution is different for them please point the difference.
Thanks for the help...
I believe a URI Association is what you want. You should be able to create a different association in your WP7 app and in your WP8 app, and handle them accordingly.
A URI association allows your app to automatically launch when another app launches a special URI.
Also note:
If you are interested only in launching your own apps, consider using
APIs from the Windows.Phone.Management.Deployment namespace. You can
use this API to check for other apps that you’ve published, and then
launch them if they’re installed.
You basically just need to update the WMAppManifest.xml file to include the URI Association and then listen for that URI. Example:
<Extensions>
<Protocol Name="contoso" NavUriFragment="encodedLaunchUri=%s" TaskID="_default" />
</Extensions>
Then you can use a custom URI Mapper to handle your association (full example in top link above):
public override Uri MapUri(Uri uri)
{
tempUri = System.Net.HttpUtility.UrlDecode(uri.ToString());
// URI association launch for contoso.
if (tempUri.Contains("contoso:ShowProducts?CategoryID="))
{
// Get the category ID (after "CategoryID=").
int categoryIdIndex = tempUri.IndexOf("CategoryID=") + 11;
string categoryId = tempUri.Substring(categoryIdIndex);
// Map the show products request to ShowProducts.xaml
return new Uri("/ShowProducts.xaml?CategoryID=" + categoryId, UriKind.Relative);
}
// Otherwise perform normal launch.
return uri;
}
Hope this helps!
Is the secondary app one that you have created? If so, do something like this:
IEnumerable<Package> packages = InstallationManager.FindPackagesForCurrentPublisher();
foreach (Package package in packages)
{
if (package.Id.ProductId.ToString().ToLower() == "product id of secondary app")
{
//Launch the app
package.Launch();
}
}
Make sure that your publisher ids match in the WMAppManifest for both apps.
If this secondary app was published by someone else, you'll need to use a custom Uri schema. The app needs to have this feature added by the developer, you can't just launch any app.

Resources