Inline web-page Android intent fallback detection

Web Push is great, however if the user already has an app installed that does Push notifications the developer needs to reasonably be able to stop either the app or the web sites notification. However there is no shared ID between site and app (for obvious reasons).
There are a couple of strategies that we are experimenting with right now. One of strategy is to try and launch an app and if it is not installed use the web experience.


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan

Web Push is great, however if the user already has an app installed that does Push notifications the developer needs to reasonably be able to stop either the app or the web sites notification. However there is no shared ID between site and app (for obvious reasons).

There are a couple of strategies that we are experimenting with right now. One of strategy is to try and launch an app and if it is not installed use the web experience.

Android Intents to the rescue. You can make an intent URI that will launch an app and if not there navigate to a page of the developer's choice. One such URL is:

intent:#Intent;package=com.kinlan.sup;S.browser_fallback_url=https%3A%2F%2Fpaul.kinlan.me

This is cool and it works well, however it causes a full on page refresh if you are not careful. Luckily document fragment identifiers work well, so you can just add the following into your page (changing all the parameters for your use case)

<a href="intent:#Intent;package=com.kinlan.sup;S.browser_fallback_url=https%3A%2F%2Fpaul.kinlan.me%2Fandroid-intent-fallback-detection%2F%23noapp;end">Try to open app, but fallback</a>

<script>
  window.onhashchange = function() {
    // If this event fires the app is not installed on the user’s device.
    if(window.location.hash == "#noapp") {
      // Check the hash is what we expect it to be   
    }
  }
</script>

Note: this will only work on Android. Now you can try to launch the app and then start your browser-side Web Push registration logic.

Try to open Android app, but fallback

This is just one step of what you need to do to manage Push Notification in your Web App if you have a complimentary native app. We will be documenting them shortly. Personally I think it is all the more reason just to go web-only.... But I think I am in a minority at the moment :)


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan


Print Share Comment Cite Upload Translate Updates
APA

Paul Kinlan | Sciencx (2016-01-12T12:20:32+00:00) Inline web-page Android intent fallback detection. Retrieved from https://www.scien.cx/2016/01/12/inline-web-page-android-intent-fallback-detection/

MLA
" » Inline web-page Android intent fallback detection." Paul Kinlan | Sciencx - Tuesday January 12, 2016, https://www.scien.cx/2016/01/12/inline-web-page-android-intent-fallback-detection/
HARVARD
Paul Kinlan | Sciencx Tuesday January 12, 2016 » Inline web-page Android intent fallback detection., viewed ,<https://www.scien.cx/2016/01/12/inline-web-page-android-intent-fallback-detection/>
VANCOUVER
Paul Kinlan | Sciencx - » Inline web-page Android intent fallback detection. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2016/01/12/inline-web-page-android-intent-fallback-detection/
CHICAGO
" » Inline web-page Android intent fallback detection." Paul Kinlan | Sciencx - Accessed . https://www.scien.cx/2016/01/12/inline-web-page-android-intent-fallback-detection/
IEEE
" » Inline web-page Android intent fallback detection." Paul Kinlan | Sciencx [Online]. Available: https://www.scien.cx/2016/01/12/inline-web-page-android-intent-fallback-detection/. [Accessed: ]
rf:citation
» Inline web-page Android intent fallback detection | Paul Kinlan | Sciencx | https://www.scien.cx/2016/01/12/inline-web-page-android-intent-fallback-detection/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.