How to send data from webpage to native app on mobile device, both Android and iOS?



The scenario is, a user is visiting my webpage, click the download button to download my apk package (on Android) or go to App Store (on iOS). Then install the app and open it.

What I want to do is, when the user visits my webpage, I store some data to somewhere, and when the app is installed and opened, it can somehow read the the data (so the custom url scheme doesn't work in this situation).

For example, the user is reading an article on my webpage and then he finds out that we have an native app. So he downloads the app and installs it. We hope that when he opens the app, it could automatically display the article he was just reading. Therefore, the native app needs to know the article id from the webpage.

Now I can think of two solutions to do this but have some difficulty to overcome:

  1. When the user visits my webpage, I copy the data to system clipboard using document.execCommand('copy') and then in my app, I acquire the data from system clipboard. While, as you may know, this API are badly supported on mobile browsers due to security reasons.
  2. Use remote server as media. Webpage sends data to the server and app fetches it. But the data is device sensitive, and I can't think of what can be used as a unique identifier for a device. Because all webpage can obtain is some navigator.userAgent information.

So, is there someone that can help me out here and find a perfect way to send the data from webpage to native app. I would be very grateful!

1 Answer: 

I think the best option you have is to :
-Store the data in a table
-Create a php page that will do the query to get the data
-Do a http query from you android/ios app to this php page, you've your data !