I have an acitivity with different fragments.in my home fragment i have a slider.i will be getting the dynamic url while clicking the slider image.i need to open another fragment with respect to the query parameter in the dynamic link.
My problem is i cannot convert this dynamic url to actual url.
For example the dymanic link is https://x97av.app.goo.gl/AbCD..I need to convert this link to https://abcd.com/lmno/a?id=2..
So i could easily fetch the id and move to respective screen.
you can use a hidden webview (not visible in UI) to load the dynamic URL, and use
mWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
// here you can use the actual url.
}
});
so, you can use the actual URL when the dynamic URL loaded.
Related
I am using android webview and loading an url. Inside the webview, there are certain click events and on clicking , the UI inside webview is changed. I am not getting any callback in shouldOverrideUrlLoading(...). Is there a way to detect the changes inside webview in android?
The shouldOverrideUrlLoading() is called only when baseUrl changes.
The onPageFinished(WebView view, String url) method is called when every url changes and loads. The Url can be parsed to find out the change.
I wish to show only the login-page element of a URL. My current approach which is not working:
web.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url)
{
view.loadUrl("javascript:document.getElementByClassName('login-page')");
}
});
web.loadUrl("https://www.reddit.com/reddits/login");
For mobile screens you should develop separate screens and embed it.
Another way is if your web page supports p/# tag (i.e) like
https://developer.android.com/guide/components/fundamentals.html#Components
https://www.reddit.com/reddits#login this should navigate the page directly to login form
Anyhow I prefer you should develop the page for mobile screens.
Your approach is close to working, but you should modify the existing page instead of trying to load a subset of the existing page as a new one.
The following hides elements with class SectionToRemove, you could instead hide all and only make visible the area you need:
#Override
public void onPageFinished(final WebView view, String url) {
super.onPageFinished(view, url);
view.loadUrl("javascript:$('.SectionToRemove').hide();");
}
That being said, Reddit has extensive APIs that should be used if possible, this approach may breach Terms of Service.
How to go EXACTLY to http://example.com/index.html#label if content to webview loading via WebView.loadDataWithBaseURL ?
By default webview go to root only. How go to label ?
WebView doesn't have such functionality from the box.
You can achieve this with the help of javascript, but this is a bit of ugly.
You should load your html page and then add javascript code to it.
After this you can load your webview and call javascript methods from current page.
Check this link for example how that can be done.
WebView jump to anchor using loadDataWithBaseUrl
Example goes here
webContents.setWebViewClient(new WebViewClient(){
#Override
public void onPageFinished(WebView view, String url) {
String id = "895884";
webContents.loadUrl("javascript:scrollAnchor(" + id + ");");
}
});
I am working on an android project right now and have a question about how to do callbacks in different webviews. I used JSInterface for my project too. Here I have 2 webviews. One has an index page, anther is a overlay(still a html page though.) What I want to do is if any user clicks on some links on the overlay, it should fire a callback function which is written in the java file where the index page was connected to through JSInterface. It might sound confusing, but I have draw something to help make it clear!
Thanks!
You can use a custom URL scheme like myurl://function for your functionality links. Then write an event handler for the WebView's shouldOverrideUrlLoading event in which you decide how to process the URL: either instruct the webview to load it, or do some custom action.
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (url.startsWith("myurl://"))
{
// Parse further to extract function and do custom action
}
else
{
// Load the page via the webview
view.loadUrl(url);
}
return true;
}
I used startsWith to check the URL for this quick and dirty example, but you should consider using android.net.Uri.parse for parsing URLs.
This should allow you to call the Java function foo() without having to go through the first WebView.
If you want to go through the first webview, then you can call a function on the JSInterface like this (where webView1 is the first WebView retrieved through findViewById):
webView1.loadUrl("javascript:myjsinterface.myjsfunc();")
I'm making an application that contains button's and those buttons control an embedded browser. My problem is that I want to see the button's and the web page in the same layout, but when i click on a button this will open a web page and don't show the button, can anyone help me?
If I understand correctly your problem is that following a link opens the standard browser not your WebView, right ?
Add this to your WebView to change that behavior
// this is to prevent that when clicking a new URL from the displayed
// page the default web browser launches
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
You need to use a Layout that supports more than one child. Take a look here