Android WebView URL problems - android

I have android app hosting a web site in WebView. It works fine, but has one issue. Whenever users search in Google and click on page of this site, the application is opening not at that page but on home page of the web site.
For example: they click on www.example.com/blog - WebView app is open but it shows homepage, not blog.
Links (navigation) works fine inside of application when it starts.

try these code
myWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(request.getUrl().toString());
return false;
}
});
when you click on any link on webview then view.loadurl() method again load new url.

Related

can we use browser other than chrome to load web activity in android

In my app I am trying to open web application which needs flash player but as I am new to android I only know opening web view with chrome client. is there any method to open webview with any other browser instead of chrome.
I am planing to open that web activity in puffin browser as it supports flash player
Write this to open URL in your own webview :
web.setWebViewClient(new myWebClient());
To enable Javascript :
web.getSettings().setJavaScriptEnabled(true);
When the user clicks a link from a web page in your WebView, the default behavior is for Android to launch an application that handles URLs. Usually, the default web browser opens and loads the destination URL. However, you can override this behavior for your WebView, so links open within your WebView.
EDIT
Add this to your code and see if its work:
Make sure shouldOverrideUrlLoading(...) should return false to prevent the default browser from being opened.
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
}

WebView App: Only Open External Links In Mob Browser

There are 2 condition first open all links within App and second is that open all links in mobile browser.
But I want to open web site internal links within App and external link in mobile browser.
For Example:
My app is a WebView of https://www.123.com and I am using amazon affiliate links in my web site(https://www.123.com)
Now I want that all links starting with https://www.123.com open within App and all amazon affiliate (external) links starting https://www.amazon.com open in mobile browser.
Just override shouldOverideURLoading in WebViewClient.
You will get the links clicked inside the webview, then process accordingly.
WebView webView = findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Log.d(TAG, "Request URL is " + request.getUrl());
if (request.getUrl().toString().equalsIgnoreCase("www.123.com/affiliated")) {
//DO SOMETHING
} else {
//DO SOMETHING
}
return super.shouldOverrideUrlLoading(view, request);
}
});
webView.loadUrl("https://stackoverflow.com/");
Please mark the answer as accepted if it worked.Thanks.

Multiwindow Apps in Android

I am developing android application to use multiple window in same window.
I am including multiple layouts with multiple purpose. For example one part of window will have browser and one part has to display Facebook or twitter news feed, and one more to display current news which can be get from rss feed.
For the browser I am using WebView in which user can search some thing in browser.
But if I use webview to search something it is opened in android browser.
Is there anyway to display webpages with in Webview and if I search anything It should also be displayed with in web view?
Guide me in right way.
Try this solution .
WebView view =(WebView)findViewById(R.id.webView1);
view.getSettings().setJavaScriptEnabled(true);
view.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
Thanks

How do I open another app in my WebView app?

I have an Android app with that displays a mobile website (WebView), in the mobile website there are links redirecting to a PDF, Excel and video files.
When try to open it in my regular browser my phone asks to open it with another app or it start a download, so I can open it afterwards.
But in my WebView app it either doesn't work, no response or it displays a "Page unavailable" error.
Is it even possible?
To handle links in WebView, you can use the shouldOverrideUrlLoading method of WebViewClient class. Consider the following example;
WebView webView = (WebView) findViewById(R.id.infoView);
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Assuming you are giving link to some PDF file.
if (url.contains(".pdf")) {
// Now do what you want to with the url here
}
return true;
}
}
This way, you can intercept any link tapped in WebView and then do whatever you want.

How to display Web site in Android WebView

I am new to Android WebView, in my application i need to display a web site conatins 3 web pages. In the first web page there will be a link to navigate to the second page and second to third page. I given the URL in the WebView, the first page is displayed perfectly, when i click the link it directly opens the browser application to display the second page. But i want to display the second page in the WebView itself. Please find my code below:
WebView forumView=(WebView)findViewById(R.id.forumView);
forumView.getSettings().setJavaScriptEnabled(true);
forumView.loadUrl("url");
As i said i am very new to WebView my code might be wrong, please help me to solve this problem.
Thanks in Advance,
Rajapandian
This piece of code will help you.
wbb = (WebView) findViewById(R.id.webView_tobe_loaded);
WebSettings wbset=wbb.getSettings();
wbset.setJavaScriptEnabled(true);
wbb.setWebViewClient(new MyWebViewClient());
String url="http://www.google.com";
System.out.println(getdeviceid());
wbb.getSettings().setJavaScriptEnabled(true);
wbb.loadUrl(url);
You'll have to intercept the clicks yourself if you don't want the default Android behavior.
You can monitor events in a WebView using a WebViewClient. The method you want is shouldOverrideUrlLoading(). This allows you to perform your own action when a particular URL is selected.
You set the WebViewClient of your WebView using the setWebViewClient() method.
If you look at the WebView sample in the SDK there's an example which does just what you want. It's as simple as:
private class HelloWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}

Categories

Resources