Issue
My app is a WebView Application and I've setup URL Intent Filters so when a link with the domain "riftacademy.org" is clicked, it opens my app.
Now I'm trying to implement deep-linking into the WebView application...
I saw something similar in the thread here How to enable deep-linking in WebView on Android app?
But unlike the above which uses a custom URI Scheme to open the application, I'd like to implement deep-linking in my WebView using my domain name "riftacademy.org"
In this scenario, when a link such as https://riftacademy.org/login or https://riftacademy.org/register is clicked, it should open the app and go to the pages that match the links. But in this case, it opens the app but only loads the homepage riftacademy.org...
I want the WebView app to be able to load links after the app has been opened, similar to how YouTube and Facebook handle links
Can Deep-Linking be achieved in WebView using Domain Names?
A snippet of where I'm guessing may be needed to edit
newWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse(url));
startActivity(browserIntent);
return true;
}
});
return true;
}
});
Thanks in advance
Solution
So I've been able to solve this with the help of Ron from https://webintoapp.com ... This was achieved using URI Intent Filters and placing the following code in the MainActivity.java and AndroidManifest.xml
I added this to the OnCreate Method in my MainActivity.java... The website name should be added just after the else{mWebView.loadUrL
SetWebView(mWebView);
Intent intent = getIntent();
Uri data = intent.getData();
if(data != null) {
//Load the deep-link url:
String url = intent.getDataString();
mWebView.loadUrl(url);
}
else
{
mWebView.loadUrl("https://riftacademy.org/");
}
And this to my MainActivity.xml... The android:host should be the website URL as well
<activity android:name=".MainActivity">
<intent-filter android:label="The Title">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="riftacademy.org" />
</intent-filter>
<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="riftacademy.org" />
This would enable the WebView App to load all kinds of links as long as the links starts with the default URL of the website
Answered By - BAKARE PAUL
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.