I have three buttons on my website, that link to Facebook, Twitter & vk.com pages. I want to open native app, if it is installed on user device. Otherwise, I want URL fallback to be opened.
First of all, I tried to use native app schemes directly with deep-link.js plugin. But, when I tried to open native app URL scheme, when native app was not installed, Safari has shown an error, but opened URL fallback page finally. Default Android browser said that he does not know how to handle such URL scheme:
<a class="btn btn-primary" href="https://www.facebook.com/warpcompany" data-app-ios="fb://profile/838619192839881" data-app-android="fb://page/838619192839881">Facebook</a>
Then I tried to use App Links "standard", that that has so much promotion from Facebook. I even tried to use their hosted app links, to make sure I've generated everything right way. It does not work, it always redirect to website fallback. You can easily test it by yourself from https://fb.me/746134728830806
Is it possible to provide deep link on website, that will open native app without errors at least in default os browsers, or fallback silently to URL?
It is still possible, but on newer versions of the Android default browser you have to use intents instead of just trying to open the deep link. For example replace your fb://page/838619192839881 with
intent://page/838619192839881#Intent;scheme=fb;package=com.facebook.katana;end
This will fallback to Google play by default, but you can override the fallback adding a S.browser_fallback_url:
intent://page/838619192839881#Intent;scheme=fb;package=com.facebook.katana;S.browser_fallback_url=http%3A%2F%2Fwww.facebook.com%2F;end
The fallback should be url encoded.
Of course you'll have issues if the user is not on an Android phone or with an old version of the default browser (or strange browser). You can setup a bunch of conditions and replace your HTML with the correct code for each case.
The accepted answer will only work on Chrome v28 and default browsers for Android 5.0. If you want this to work on other browser like Facebook/Twitter webviews, Firefox, UC and older default browsers than 5.0, you'll need to use some code that's a little more complicated.
Add this function to your JS snippet:
var openSesame = function() {
var method = 'iframe';
var fallbackFunction = function() {
if (method == 'iframe') {
window.location = "market://details?id=com.facebook.katana";
}
};
var addIFrame = function() {
var iframe = document.createElement("iframe");
iframe.style.border = "none";
iframe.style.width = "1px";
iframe.style.height = "1px";
iframe.src = "fb://page/838619192839881";
document.body.appendChild(iframe);
};
var loadChromeIntent = function() {
method = 'intent';
document.location = "intent://page/838619192839881#Intent;scheme=fb;package=com.facebook.katana;end";
};
if (navigator.userAgent.match(/Chrome/) && !navigator.userAgent.match("Version/")) {
loadChromeIntent();
}
else if (navigator.userAgent.match(/Firefox/)) {
window.location = "fb://page/838619192839881";
}
else {
addIFrame();
}
setTimeout(fallbackFunction, 750);
};
Then your button will look like this:
Open the App
Or you can use a service like branch.io which does exactly what you're looking for automatically.
Yes it is! Have a look to this training:
https://developer.android.com/training/app-indexing/deep-linking.html
Is this the information you needed? lmk
Related
I'm creating a simple webview app using nativescript-vue where there is nothing else in the app except the webview that loads a website fullscreen.
On iOS it works great, I can log in to the website turn the app off and on and I'm still logged in.
On Android, the cookies are not saved and you have to log in again every time you turn the app off.
Any way I can enable cookies in the webview for Android?
I couldn't make it work with cookies, so I had to switch and use localstorage as a backup for saving tokens instead of cookies.
Here is how my final version looks:
<template>
<Page>
<WebView #loadStarted="onLoadStarted"
#loaded="onWebViewLoaded"
src="https://yoururl.com/"
/>
</Page>
</template>
<script>
import { isAndroid } from "tns-core-modules/platform"
export default {
methods: {
onLoadStarted (webargs) {
if (isAndroid) {
const webView = webargs.object;
webView.android.getSettings().setDomStorageEnabled(true) // This will enable local storage
}
},
onWebViewLoaded(webargs) { // I use this only to disable the default zoom buttons
if (isAndroid) {
const webView = webargs.object;
webView.android.getSettings().setDisplayZoomControls(false)
webView.android.getSettings().setBuiltInZoomControls(false)
}
},
}
};
</script>
Apparently, you should be able to enable cookies doing this (at least for newer SDK users):
webView.on(WebView.loadStartedEvent, (args) => {
webView.android.getSettings().setAcceptThirdPartyCookies(webView, true)
});
But that didn't work as expected as it seemed like sometimes it would save cookies and sometimes it won't or sometimes it would remove cookies (when you log out) and sometimes not.
I hope this info helps someone as it sure seems there is little to none info about this especially if you aren't much familiar with pure Java Android development.
This code should work
const webView = webargs.object;
if (android.os.Build.VERSION.SDK_INT >= 21) {
android.webkit.CookieManager.getInstance().setAcceptThirdPartyCookies(webView.android, true);
}
I'd like for users to be able to share a link (e.g. app.com/SKFLA - this is primarily because deep links on their own aren't clickable) via Facebook etc. When clicked, this redirects to a deep link app://SKFLA. If the app is installed, this opens the app - this is all working fine so far. But if the app isn't installed, I'd like to open the app store on the relevant page. Is this achievable? Thanks!
You need UNIVERSAL LINKS
Please check
IOS https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html
Android
https://developer.android.com/training/app-links/
It might also require some extra server-side setup.
Not sure about native behavior.
We used third-party service like https://branch.io/deepviews/.
There is a bunch of similar services.
If someone is still stuck in this issue and needs easiest solution, you will love node-deeplink
1.) If app is installed: Calling an app through deep linking will always call componentDidMount of root component. So you can attach a listener there. Like:
Linking.getInitialURL()
.then(url => {
if (url) {
this.handleOpenURL({ url });
}
})
.catch(console.error);
Linking.addEventListener('url', this.handleOpenURL);
handleOpenURL(event) {
if (event) {
console.log('event = ', event);
const url = event.url;
const route = url.replace(/.*?:\/\//g, '');
console.log('route = ', route);
if(route.match(/\/([^\/]+)\/?$/)) {
const id = route.match(/\/([^\/]+)\/?$/)[1];
const routeName = route.split('/')[0];
if (routeName === 'privatealbum') {
Actions.privateAlbum({ albumId: id });
}
}
}
}
2.) If app is not installed: Just set up a route in your server and node-deeplink package will handle the bridging between web browser to app store when a app is not installed in your mobile.
By this, both the cases will be handled without any struggle
Here is my situation:
User request an email of forgot password.
User use their Android/iPhone to open email and tap on the link inside the email
When the link is tapped (clicked), it'll call the Ionic app.
I spend the whole morning to research and found this solution: using a plugin of Cordova named Custom-URL-scheme.
I also found out a tutorial from sysgears that I need to add this code into my app.js file:
.run(['$state', '$window',
function($state, $window) {
$window.addEventListener('LaunchUrl', function(event) {
// gets page name from url
var page =/.*:[/]{2}([^?]*)[?]?(.*)/.exec(event.detail.url)[1];
// redirects to page specified in url
$state.go('tab.'+ page, {});
});
}
]);
function handleOpenURL(url) {
setTimeout( function() {
var event = new CustomEvent('LaunchUrl', {detail: {'url': url}});
window.dispatchEvent(event);
}, 0);
}
I've done everything, however it does not work. I tried to type my URL_SCHEME (http://myapp://) into the Chrome browser in Android phone but Chrome just display an error message:
This webpage is not available. ERR_NAME_NOT_RESOLVED.
Please help me. Thanks.
Try to remove the "http://" from your sheme, href and browser
If still not working, can you precise your cordova version, and the plugin version you use. Did you install the plugin with the sheme in --variable URL_SCHEME=myapp
Also, note its "SHEME", not SHEMA
I am using the google drive picker to open files from google drive within a web page. The dialog works correctly in most browsers including mobile Chrome, however, with the Android browser, tapping on a file does not select it.
This is using a Samsung Galaxy Note 1 with factory settings + updates. I can replicate this problem with an unrelated application, mindmup which I will use this as the reproduction steps given its publicly accessible:
i)
http://www.mindmup.com/
From any machine, create and save a mindmap to your google drive
ii)
With the Android browser, revisit the site and choose File -> Open ->From Google Drive
iii)
The google drive picker will appear and display your file. The dialog will be scrollable and can be cancelled but tapping a file will not select it.
How can I fix this problem in the Android browser?
The official Google response is that the picker does not support Android. Huh. Works on IOS. Maybe they could add that little tidbit to their documentation.
No other recourse but to implement my own using the files.list api:
retrieveAllFiles = function(callback) {
var retrievePageOfFiles = function(request, result) {
request.execute(function(resp) {
result = result.concat(resp.items);
var nextPageToken = resp.nextPageToken;
if (nextPageToken) {
request = gapi.client.drive.files.list({
'pageToken': nextPageToken,
'q' : 'trashed = false'
});
retrievePageOfFiles(request, result);
} else {
callback(result);
}
});
};
var initialRequest = gapi.client.drive.files.list({
'q' : 'trashed = false'
});
retrievePageOfFiles(initialRequest, []);
};
We are trying to implement a simple solution to our website developed via Flex and mobile apps developed using Adobe Air.
1) Our users would like to import their facebook friends onto website via www.ourwebsite.com and also via the Ourwebsite android, ios & blackberry apps.
2) We want to use the Facebook Requests dialog which allows users to select their friends and send multiple invitations at a time
3) When the recepient clicks on the notification he receives
in case of web, it should direct the notification recipient to www.ourwebsite.com
in case of mobile app, it should re-direct to respective appstore to download our app.
We tried several configurations but it's not working for us.
As previously said we have developed our website using Adobe Flex and our Mobiles apps run using Adobe Air. Do we need to install the Facebook native SDK's into our code?
Strangely the exact same requirement is working for www.naaptol.com and 9lessons.info.
But we're unable to achieve the same technique.
Can anyone guide us or advise if we're missing any important aspect of Facebook App & its policies.
Thank you.
Sai Krishna
So if I think I am understanding this right, you want to be able to open a link differently based upon the platform they are on. Here is some js that will do it for ios and android. If they have your app installed it will launch the app, otherwise it will send them to the app store
// if iPod / iPhone, display install app prompt
if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i) || navigator.userAgent.match(/android/i)) {
var store_loc = "itms://itunes.com/apps/youriOSApp";
var href = "yourPrefix://";
var is_android = false;
if (navigator.userAgent.match(/android/i)) {
store_loc = "https://play.google.com/store/apps/details?id=air.com.your.app";
is_android = true;
}
var app_loc = href;
if (is_android) {
var w = null;
try {
w = window.open(app_loc, '_blank');
} catch (e) {
// no exception
}
if (w) {
window.close();
} else {
window.location = store_loc;
}
} else {
var timeout = null;
window.location.replace(app_loc);
timeout = setTimeout(function () {
"use strict";
window.location = store_loc;
}, 300);
onblur = function () {
"use strict";
clearTimeout(timeout);
};
}
}