Reputation: 729
I am working in xamarin forms where I have to use Deeplink for android. Deeplink is working from any messanger app (skype,whatsapp,etc) but failed in mobile any browser. below is my code. I have publish javasript code deeplink.html
<!DOCTYPE html>
<html>
<head>
<title>Veepee App</title>
</head>
<body>
<!--<button id="checkApp">Check if Veepee App is Installed</button>-->
<script>
const urlParams = new URLSearchParams(window.location.search);
//document.getElementById('checkApp').addEventListener('click', function() {
window.addEventListener('load', function() {
var pageName = urlParams.get('page'); // Replace with the actual page name you want to pass
// Function to detect if the device is Android
function isAndroid() {
return /Android/i.test(navigator.userAgent);
}
// Function to detect if the device is iOS
function isIOS() {
return /iPhone|iPad|iPod/i.test(navigator.userAgent);
}
if (isAndroid()) {
// Android-specific code
var appPackageName = 'com.companyname.veepee';
var appLink = 'intent://wholesale.veepeeonline.com/'+ pageName +'/#Intent;scheme=http;package=' + appPackageName + ';end';
// Attempt to open the app
window.location = appLink;
// Fallback to Play Store if the app is not installed
setTimeout(function() {
alert('App is not installed.');
window.location.href = 'https://play.google.com/store/apps/details?id=' + appPackageName;
}, 2000);
} else if (isIOS()) {
// iOS-specific code
var appLink = 'veepeedomain://veepeedomain/'+ pageName ;
// Attempt to open the app
window.location = appLink;
// Fallback to App Store if the app is not installed
setTimeout(function() {
alert('App is not installed.');
window.location.href = 'https://apps.apple.com/in/app/veepee-international/id6450380169';
}, 2000);
} else {
alert('Unsupported device.');
}
});
</script>
</body>
</html>
assetlinks.json
[
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.companyname.veepee",
"sha256_cert_fingerprints": [
"debug sha....",
"release sha..."
]
}
}
]
AndroidMenifest.xml
<activity android:name="SplashActivity" android:exported="true" android:launchMode="singleTop">
</activity>
MainActivity.cs
[Activity(Label = "Veepee", Icon = "@drawable/logo", Exported = true, Theme = "@style/MainTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, LaunchMode = LaunchMode.SingleTop)]
[IntentFilter(new[] { Android.Content.Intent.ActionView },
DataScheme = "http",
DataHost = "wholesale.veepeeonline.com",
DataPathPrefix = "/",
AutoVerify = true,
Categories = new[] { Android.Content.Intent.ActionView, Android.Content.Intent.CategoryDefault, Android.Content.Intent.CategoryBrowsable })]
[IntentFilter(new[] { Android.Content.Intent.ActionView },
DataScheme = "https",
DataHost = "wholesale.veepeeonline.com",
DataPathPrefix = "/",
AutoVerify = true,
Categories = new[] { Android.Content.Intent.ActionView, Android.Content.Intent.CategoryDefault, Android.Content.Intent.CategoryBrowsable })]
App.xaml.cs protected override void OnAppLinkRequestReceived(Uri uri) { base.OnAppLinkRequestReceived(uri);
if (uri.Host.ToLower() == "wholesale.veepeeonline.com" && uri.Segments != null && uri.Segments.Length == 2)
{
var queryParams = System.Web.HttpUtility.ParseQueryString(uri.Query);
string name = queryParams["page"];
//string action = uri.Segments[1].Replace("/", "");
string action = name;
bool isActionParamsValid = long.TryParse(uri.Segments[1], out long productId);
Constants.PageNameFromURL = action;
Constants.OpenFromURL = true;
//if (action.ToLower() == "pendingreportview")
//{
//}
}
}
Please give me solution Thanks in advance
Upvotes: 0
Views: 27