Issue
What I'd like to achieve
When a user clicks on any link from my website, I'd like it to direct the user specific link in my app (If it's installed). If it's not installed then direct the user to link in the browser.
Example:
User gets an email with a link in it called: www.myapp.com/someplaceinmyapp It goes to that page in my app if It's installed. If not, then go to that page in the browser.
Keep in mind that it will be for all pages in my app. So this applies for any link from my webpage.
My questions
Is there a specific name for this? I know about deep linking and app links, but I'm not sure which one is for me.
Is this even possible? I'm not even sure if It's possible at the moment.
Will the code for this be in the webage or the app? e.g: Javascript or Kotlin or something in the manifest file.
How do I do this? This is probably the thing I need the most.
Notes
I have got something in my webpage which shows a popup (only in browser) that says "Use the app". If not installed, then goes to the play store. If installed, then goes to the homepage of my website in my app. I found how to do it from here using the answer with the most votes (not the accepted one) so in my manifest I have:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http"
android:host="www.myapp.com"
android:pathPrefix="/install.html" />
</intent-filter>
If there's anything you'd like me to add to this question, just let me know :)
Solution
I found that the way to do this, was using the App Links assistant, which you can find in android studio under Tools -> App Links assistant. This is what you should see on the side once you open it:
Step 1
Click "Open URL Mapping Editor", then add a URL mapping (Click the "+"). In the host, put your website link e.g: https://www.example.com. For Path, in the select box, select just "path" and put nothing in the type box.
Step 2
The Select Activity button does not work for Kotlin, so here's the code that you manually need to put in.
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
handleIntent(intent)
}
private fun handleIntent(intent: Intent) {
val wbWebView = findViewById<View>(R.id.your_webview) as WebView
val appLinkAction = intent.action
val appLinkData = intent.data
if (Intent.ACTION_VIEW == appLinkAction && appLinkData != null) {
wbWebView.loadUrl(appLinkData.toString())
} else {
// default link that it goes to when opening app
wbWebView.loadUrl("https://www.example.com")
}
}
and in your onCreate add handleIntent(intent)
Step 3
Click the "Open Digital Asset Links File Generator". Most of the information will be already filled, so you can go on to click the "Generate Digital Asset Links File". Make a folder called ".well-known" in your website and then put a file in there called "assetlinks.json", paste the preview into there. So when you go to https://www.yourwebsite.com/.well-known/assetlinks.json you should be able to see the Digital asset links file. You can also see other websites Digital asset links file. Like for google, https://www.google.com/.well-known/assetlinks.json.
Then proceed to click the "Link and Verify" button, If all goes well you should see this appear beneath the button:
Step 4
Time to test! Go ahead and click on "Test app links" and put in a URL from your website. If all goes well, you shouldn't see a disambiguation dialogue.
I also like to do further testing by sending myself an email with the link in it.
Notes
You can only use the App Links Assistant if your website is using https instead of http.
I added android:launchMode="singleTask"
into my activity tag in the manifest, this means that If you click on a link from your website in an email then it will open in a new window.
They have a doc about this here which includes a video (Keep in mind that they are using java)
Answered By - Amy
Answer Checked By - Gilberto Lyons (JavaFixing Admin)