Check if app is installed from webpage - javascript

I have an iOS and Android app and I'm building a corresponding website. I would like that the webpage, if opened using a mobile device, opens the app or its corresponding app store page (without using Facebook app links).
On the app side everything is working, including the url schema.
Does someone know how to implement this procedure, without external services, using HTML and JS?
Thanks in advance for your help.

To be honest, this is kind of a pain to implement on your own. There is no easy way to handle everything without a ton of nasty edge cases, most notably the 'Cannot Open Page" error users will see if they don't have your app installed. Until iOS 9, a reasonable basic implementation was putting a JavaScript redirect like this into a dedicated redirect page on your site:
setTimeout(function() {
window.location = "https://yourdomain.com";
}, 25);
// If "yourapp://" is registered, the user will see a dialog
// asking if they want to open your app. If they agree, your
// app will launch immediately and the timer won't fire.
// If not installed, you'll get an ugly "Cannot Open Page"
// dialogue and your fallback page will open when the timer expires.
window.location = "yourapp://";
Unfortunately this would still show a 'Cannot Open Page' error, but until recently it was possible to get around this in a reasonably user-friendly way by using a more nuanced version of this script. Sadly, Apple intentionally broke that with the iOS 9.2 update, so custom URL schemes are actually pretty much useless for deep linking now, unless you are certain the app is already installed on that device.
Apple is obviously trying to push the newer Universal Links standard as much as possible. Universal Links lets you use a normal http:// URL to a page on your website (the page could be a simple redirection to your desired fallback webpage without the custom URL trigger that causes the 'Cannot Open Page' error), which is intercepted by your phone and sent directly into your app if installed.
This is quite a lot to handle, so the best option might be a free service like Branch.io (full disclosure: I work with the team) to take care of all the technical aspects. You can find examples of apps using the Branch service here.

Related

<a href="fb//"> open post/video Link in native App? [duplicate]

Some dev blogs have published information about the "fb://" url scheme for opening various views in the Facebook iPhone App. No matter how much I've searched, I haven't found one word from any official Facebook source about this.
Since the information is public anyways, I'm sure I'm not the only one who'd like to know, whether using this url scheme is officially approved, am I allowed to use it, does it work correctly, and if it's not approved, will it be and what's the approximate schedule for that?
Thanks in advance for any info on this subject!
It's there to support the iOS push notification system (i.e. you get a push notification that says "Friend's Name tagged you in a photo", and you tap on it, it takes you straight to the photo).
I'd assume it's not intended for third party use and therefore subject to change. Hell, Facebook's public-facing APIs are subject to change on a whim anyhow, so I'd be especially cautious about something they hadn't documented.
It's for iOS only. The iOS API lets you define you own URL scheme, so Facebook must have developed their application to register the fb:// URL scheme on iOS devices. It's not a feature that was created by Apple, it's something you, the developer, can make up.
Here are some resources you can investigate
The Facebook iOS SDK
Here on StackOverflow
A tutorial on how it works (not Facebook-specific)
You can use it from your own applications on iOS, but only if the Facebook application is installed. There are, however, plugins and browser extensions out there that mimic the behavior by handling the fb:// schema on your desktop browser.

Open Android app through deep link if it's installed or fall back to web if not installed

I'm trying to create a web page that automatically opens an Android app but only if app is installed. In case it's not it should redirect to another web page.
The app is already in production and is properly handling deep links like example://content?id=42. The format of the link could not be changed.
What I've already tried
1) Redirects and timeout:
window.location.replace('example://content?id=42');
setTimeout(function() {
window.location.replace = 'http://example.com/content?id=42';
}, 500);
Works fine for iOS but for Android it redirects to example:// immediately and thus gives me ERR_UNKNOWN_URL_SCHEME. Seems to be no go for Android.
2) iframe approach. Impossible in rencent Chrome versions. Also doesn't seem to work in Samsung browser.
3) Intents with S.browser_fallback_url. Works well but in Chrome only. Doesn't work in Opera and Samsung browser... most probably nowhere else but Chrome 25+.
use http://example.com/content?id=42 as the link and add the intent filter to your activity in manifest
<intent-filter>
<data android:scheme="http" android:host="example.com" />
...
</intent-filter>
However, a list of app registered, e.g. browsers, will show up when the link is first accessed on the machine.
You need to be aware of the browser of the client, and its operating system and adapt your site to them. For example, if the browser is Chrome and the OS is Android, use the Intent solution; if the browser is Safari use the example:// schema. You can get the info looking at the User-Agent header of the request, but I'm sure there are many open source libraries that can help you to get infos related to browser and OS.
Seems like you could at least approximate the experience by letting the user give a one-time assist:
Have your web page itself have the fallback url content.
When the page is hit check the user agent to see if the os is Android
If its Android, show the user a choice prompt/dialog to use web or Android
If they choose web (remember the choice with local storage), dismiss the dialog and show the fallback
If they choose android (remember the choice), redirect to the app with the intent:// URL (without fallback_url), will take them to market to install if necessary
After the first interaction, it'll work as you describe - automatically taking them to the web page or the installed app.
You can try using this scheme(to be sent to the user):
intent://details?id=X&url=Y&referrer=Z#Intent;scheme=market;action=android.intent.action.VIEW;package=com.android.vending;end";
X: Package name of the App
Y: Deep link scheme which should be defined in the App's manifest.
(Please refer this)
Here, they have used this URL as an example: "http://www.example.com/gizmos" , therefore Y should be replaced by this URL.
Z: Can be any data which you want to pass to the App via Google Play.
Please take note that any data which you pass should not be '&' separated because the original parameters are itself '&' separated.
PS: The Google Play makes a broadcast to the app. So make sure you receive the broadcast in a receiver.

Can I embed a chrome extension app as part of my main AngularJS app?

I have been doing a lot of reading and studying to figure out.
I basically just want my main AngularJS application to run, but also include an embedded Chrome Extension app - in this case, have regularly scheduled alarms (using the chrome.alarm API).
I want all users of my AngularJS app to have automatic access to the Chrome extension app, embedded in the main clientside one with lots of other Angular features.
It seems like I have to manually enable my Chrome app in Developer mode on my browser and even drag my Chrome app specifically to a location in my Chrome browser. I don't understand how end users can just automatically use my Chrome app then.
I need to add here I have never really used jQuery, only AngularJS but AngularJS extensively. My AngularJS app is the frontend, the backend is provided by Rails.
Some advice would be really helpful. I hope I am not downvoted as it is strange how sometimes questions get downvoted and I am not sure why...I don't really know where else to go with this question.
EDIT:
Ok some code to demonstrate:
myangularapp.controller('myappcontroller', function($scope, $http) {
var delayvar = 5;
chrome.alarms.create("arandomalarm", {delay: delayvar});
};
This doesn't just work as part of my AngularJS, I tried creating a manifest.json file in the app/assets folder too. As well as a background.js file there and my-chrome-app.js file. "chrome.alarms" is undefined, but I haven't enabled Developer mode yet. But still, how are end users supposed to use it if just to make me use it I need to do so much specific browser configuration?
You should have a look at Content Scripts and then at Message Passing which explains you how to communicate between a web page and an Chrome extension.
its not possible to automatically install a chrome extension. the user must install it from the chrome store.
you may make it easier for them to install it by providing an inline installation from your webpage. its in the official documentation and you can see an example on this page with the "add to chrome" button:
http://plusfortrello.com (one of my chrome extensions which has inline installation inside that page).
that example button is further customized to display a message instead if the user is not on chrome desktop.
if your extension also has permission to your webpage then you can also detect from your webpage if the extension is already install it (to hide the button, send messages to it and such).

Save site as a mobile shortcut android

I spent a lot of time to search for solution but without result.
I check this topics :
Website Bookmark/ Shortcut Icon for Android Help. Cant get passed standard ribbon icon
Whick is very nice ,but here user must click on bookmark.That`s not what i need. May be button,or automatic script that prompt user for this and created automaticaly.For example something like this :
http://socialmedia.biz/2012/02/21/encourage-visitors-to-save-your-site-as-a-mobile-shortcut/
But it`s work only on Apple devices .. What im looking for is a similar solution for android.
Is this possible at all?
May be the only solution is to create simple app that act like a shortcut to my web page?
The page that is talking about has a mobile version ..
Have you looked here [for Chrome]? https://developers.google.com/chrome/mobile/docs/installtohomescreen
May be the only solution is to create simple app that act like a shortcut to my web page? The page that is talking about has a mobile version ..
If this is "allowed" and doesn't go against too many guidelines, this might be your only option. Basically you'd want to create a one Activity application and all it does is call the default Intent for your web page. This should push the user into the default Browser.
You could put the app in the Google Play store and link to it from the site or a script. I'd call the app something like "SITE_NAME Web Shortcut" and make it clear in the description that the only purpose is to launch the browser -- as previously mentioned this doesnt "feel" like something that should be in an app store, and if users think they're getting something extra you'll definitely get bad reviews.
(I'd also make the Activity with #style/Theme.Transparent)
Please be aware that Chrome has changed the way that installs web apps.
Here are the details: https://developers.google.com/web/updates/2018/06/a2hs-updates
There is an install criteria now:
The web app is not already installed
Meets a user engagement heuristic
Be served over HTTPS
Includes a Web App Manifest that includes:
short_name or name
icons - must include a 192px and a 512px icon
start_url
display - must be one of fullscreen, standalone, or minimal-ui
prefer_related_applications must not be present, or be false
-Registers a service worker with a fetch handler

Meteor rendering in Adobe DPS Overlay after redirect from Facebook Login

I'm running into a pretty specific problem (2 problems, actually, but I believe they're related) and am hoping someone out there can shed some light on what's going on.
I have a Meteor application running inside an HTML overlay inside of an Adobe Digital Publishing Suite (DPS) article. I've tested this with as simple of a configuration as possible, and am able to reproduce the issue consistently.
Overview
1- Meteor works fine in Mobile Safari, and Mobile Chrome on an iPad (3rd gen, ios 6.1.7) but the rendering inside of an Adobe DPS article is generating an error:
TypeError: 'undefined' is not a function
While this error doesn't affect rendering, I believe it's related to my 2nd problem:
2- Upon redirect from facebook authentication (alt. / non-JSSDK flow) the page will not render at all, but there is no additional error message other than #1 above.
Code Example / Details
1. "Headless" browser
I'm Using an HTML overlay in an article, set up inside of InDesign and published to DPS using Folio Producer. The overlay is pointing to a test url (e.g. http://dmx.dod.fbchat.meteor.com), and is refreshed each time the specific page on the article is brought into view.
The details of the browser are as follows:
appVersion: 5.0 (iPad; CPU OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B329
userAgent: Mozilla/5.0 (iPad; CPU OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B329
I do know that there are some restrictions on this browser (for example, alert = null;), and it's considered "headless" because it's not a legitimate version of chrome or safari, with no address bars, etc.
2. The redirect is achieved via the following method
create a brand new Meteor project (e.g. meteor create DPSFBRender)
decide on the meteor uri you're going to host it from (e.g. dmx.dod.fbchat.meteor.com)
create an application on facebook (https://developers.facebook.com/apps), note the App ID.
add your meteor uri to the domain and to the redirect uri on facebook. for example:
domain: dmx.dod.fbchat.meteor.com
redirect uri: http://dmx.dod.fbchat.meteor.com/
add the following two lines to the click event for the button inside your default meteor project js file:
var randID = Meteor.uuid();
window.location.href = 'https://www.facebook.com/dialog/oauth?client_id=[FB APP ID]&redirect_uri=[URL WHERE YOU'LL HOST TEST]&state='+randID+'&response_type=token&scope=[LIST OF PERMISSIONS];
So, for example, if my testing URL were dmx.dod.fbchat.meteor.com, my FB App ID were 514080555337856 and my list of permissions were lengthy (see below), my 2nd line would look like this:
var randID = Meteor.uuid();
window.location.href = 'https://www.facebook.com/dialog/oauth?client_id=514080555337856&redirect_uri=http://dmx.dod.fbchat.meteor.com/&state='+randID+'&response_type=token&scope=create_note,email,friends_about_me,friends_actions.books,friends_actions.music,friends_actions.news,friends_actions.video,friends_activities,friends_birthday,friends_education_history,friends_events,friends_games_activity,friends_groups,friends_hometown,friends_interests,friends_likes,friends_location,friends_notes,friends_photo_video_tags,friends_photos,friends_questions,friends_relationship_details,friends_relationships,friends_religion_politics,friends_status,friends_subscriptions,friends_videos,friends_website,friends_work_history,photo_upload,publish_actions,publish_stream,read_friendlists,read_mailbox,share_item,status_update,user_about_me,user_friends,user_groups,user_interests,user_photos,user_relationship_details,user_status,video_upload,xmpp_login';
deploy your meteor app to the test uri (e.g. meteor deploy dms.dod.fbchat.meteor.com)
point your html overlay inside your DPS article to your URL
deploy / publish your article, open it up inside DPS viewer on the iPad, and click on the button, to activate the redirect.
You'll be prompted to allow the FB app permissions, accept.
You'll be navigated back to your meteor url, but the page will not appear.
If you change article pages, go out of the article and back in, or just bring up your app bar, and then go back to the article, the page will refresh, and render.
As long as you have your permissions set (as long as you aren't prompted to accept), the page will render fine. It is only after the FB prompts from the custom login and the subsequent redirect that the page won't render.
If you want to test it again, log into your fb account in a regular browser, and delete the app.
3. Debugging / Discovery
I started debugging this, using debuggify, and that's when I was able to see the TypeError: 'undefined' is not a function error. It doesn't stop anything from rendering at first glance, but I believe on the redirect that it is the culprit (see thoughts section below).
This error will appear on ANY meteor page that is rendered inside a DPS overlay. It doesn't have to be a redirect, or have anything on it. You can simply create a new meteor project, deploy it, point an HTML overlay in DPS to it, and the error will appear (only noticeable with a remote debugging tool like debuggify).
Likewise, this error will not occur inside of the IOS safari mobile browser, or the chrome browser. The above-mentioned rendering problem after redirect from FB will also work as expected in both browsers (the page will render after the "accept permissions" screens).
The 'undefined'... error has no stack trace:
Stack: TypeError: 'undefined' is not a function at ? (http://dmx.dod.fbchat.meteor.com/:1:0)
..although we do know that it happens after the load event:
Happened: After onload
Thoughts
I'm thinking this may be a combination of the dynamic JS loading inherent in Meteor, combined with the redirect. Simply, the redirect isn't waiting long enough for the JS to load (especially handlebars) and it therefore isn't rendering.
I don't believe the entire page is shut down, because in my app (not the tests) I am harvesting the App Key inside the URL Hash, and successfully storing it. So, I know that Javascript isn't completely shut down on the page. It's just the rendering portion for some reason that is not working.
I believe the 'undefined' is not a function error is related - could be Jquery, Handlebars, DDP.... something isn't loaded when expected. On a normal page load (e.g. a refresh) the browser is overcoming this. On the redirect from FB, it isn't.
It may have to do with the JS/Browser restrictions for the embedded DPS browser. Adobe limits some functionality (for security and for performance reasons), and maybe they're turning something off that meteor needs to run.
Workarounds I've tried:
Using the Default Meteor FB Login -- doesn't recognize the 'headless browser', and popups are disallowed in DPS anyway.
Using the standard JSSDK login flow from FB -- same deal, popups aren't allowed
Ideas?
So, at this point, I'm open to anything, even if it's not solving this specific problem.
Workarounds, similar problems you've experienced, thoughts, speculation on why this may be happening on the redirect, but not normally, etc.
I know there may be several ways to skin this cat, but I'm stuck right now, and would love to hear some suggestions. I just need to get FB login to work, inside of DPS. I don't care how, even if all the code is client side (this is just a test, not a production system)
I've even considered trying to edit the accounts-facebook and accounts-base packages in meteor to recognize a headless browser, but don't even know where to start on that...
Also, the 'undefined'... error happens on every single meteor page inside a DPS article, no matter what. That's annoying, and may be useful for some mobile headless browser compatibility improvements, if someone has any idea why it's occurring.
Follow ups are welcome as well. I'll be monitoring this thread.
It turns out that Tom Coleman helped me find this specific problem.
When JS is minified, if there's a missing semicolon, it can wreak havoc, and cause the above-mentioned 'undefined' error.
So, after further testing, I've discovered that this is most likely inside of the Adobe-specific DPS Javascript that is loaded with every overlay.
I've filed a bug with Adobe and will see if/when it's fixed, if it fixes the rendering problem as well.

Categories

Resources