Is there a way to hide addressbar in webchromeclient? - android

I am developing an android application in which I want to show a website, which have links in it. When any link is clicked, then it plays an online stream.
Till now I have developed an app which work alright. In this I have used webview to display first screen. The live stream is not supported in webview, so I used webchromeclient.
Now the problem is when any link is clicked, a new browser opens and plays the stream and also shows the address bar and address of page loaded page.
I want to hide the address of new loaded page.
and if possible, also I wnt to keep webchromeclient in existing screen, not a new browser.

in this case you have to customize the WebViewClient like this
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// This is my web site, so do not override; let my WebView load the page
return true;
}
}
}
Then create an instance of this new WebViewClient for the WebView:
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new MyWebViewClient());
for further have a look on this, and read carefully

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;
}
}

Prevent link to be opened in external browser with WebChromeClient

I've developed a small group of .html pages that are stored in a server.
My android app, using a webview with: setWebChromeClient loads these pages.
minSdkVersion 19
targetSdkVersion 24
The problem:
Everytime I need to load a new page, using a link in my .html page, the new page is opened in an external browser.
Url Overriding
I know about the shouldOverrideUrlLoading() method, when we're using the setWebViewClient().
But unfortunately I can't use the normal webview. I need to use the WebChromeClient() because of some feature that only work with this one. (Like the input file)
My doubt is...
How can I override my URL to force them to load inside of the webChromeClient?
I tried this but with no luck:
webView.setWebChromeClient(new WebChromeClient() {
// (...)
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
You can use following code to achieve this.
WebView web = (WebView)findViewById(R.id.web);
WebSettings webSettings = web.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportMultipleWindows(true); // This forces ChromeClient enabled.
web.setWebChromeClient(new WebChromeClient(){
#Override
public void onReceivedTitle(WebView view, String title) {
getWindow().setTitle(title); //Set Activity tile to page title.
}
});
web.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
I was using an embedded mobile web application in an Android App making use of the WebChromeClient class and did not want to fiddle around with recompiling the APK.
While looking for the easiest header(); solution (since the mobile web application is in php) I found out that using:
header("Location: url.php", TRUE, 307);
was a quick fix solution without recompiling the Android app.
This allowed the user to re-direct within the app without calling the web browser externally from my app.
Here is the link to the answer by Arindam Nayak where I got the idea from.

Auto login on web page

I am trying to write an app I want it to open a web page and auto login I am not sure how to go about sending the info to the browser from the app code.
So basically you are going to need to load in the webpage within a WebView (You can find instructions for that here and then probably push javascript into the WebView that will fill in the fields and load the page.
In your activity's onCreate:
WebView webview = new WebView(this);
setContentView(webview);
webView.setWebViewClient(new WebViewClient(){
#Override
public boolean onPageFinished(WebView view, String url) {
// Check here if url is equal to your site URL.
}
});
webview.loadUrl("http://yourwebsite.com/");
This line enables javascript in your WebView:
webView.getSettings().setJavaScriptEnabled(true);
Then you can use the WebViewClient to detect when the page you want has fully loaded. When that happens, you can use:
webView.loadUrl("javascript:document.getElementsByName('username').value = 'username'");
webView.loadUrl("javascript:document.getElementsByName('password').value = 'password'");
webView.loadUrl("javascript:document.forms['login'].submit()");
And it should automatically log you in. It's worth noting that this generally isn't easy to do on a lot of sites since they will randomize the login control ids and it also doesn't generally sit well with users if an application is logging into a website automatically for them.

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