Android Webview doesn't show contents clearly - android

In recents, i had a problem with android webview i wanted to play youtube embed video center of the screen but webview had showed me black blank area in right side of video. Now i need to open documents by using Google docs but i have same problem in documents like:
Here is my webview codes:
WebView mWebView = (WebView)findViewById(R.id.webView1);
if (Build.VERSION.SDK_INT < 8) {
mWebView.getSettings().setPluginsEnabled(true);
} else {
mWebView.getSettings().setPluginState(PluginState.ON);
}
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
mWebView.setHorizontalScrollBarEnabled(false);
mWebView.setVerticalScrollBarEnabled(false);
mWebView.getSettings().setDefaultZoom(ZoomDensity.CLOSE);
mWebView.setInitialScale(-20);
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
//mWebView.loadUrl(" http://docs.google.com/viewer?url=http%3A%2F%2Fresearch.google.com%2Farchive%2Fbigtable-osdi06.pdf");
String pdf = "http://www.projectcounter.org/SSPJune_2007.ppt";
mWebView.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdf);

Related

Getting URL from pop-up appeared in Webview android

I'm creating an android application which opens a HTML page in Webview and after clicking the button on HTML page it opens up pop-up kind webview like below. I want to Toast URL loading in popup window. Can someone help on this?
I'm adding the screenshots how the webpage is displayed on desktop/laptops and how on Android application for reference.
This is how Page is displayed on Chrome Desktop
This is how Page is displayed on Android Application Webview
I have tried the following code to handle the second window :-
WebView webview = findViewById(R.id.webview);
WebSettings webSettings = webview.getSettings();
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setSupportMultipleWindows(true);
webview.getSettings().setDisplayZoomControls(true);
webview.getSettings().setUseWideViewPort(true);
if (android.os.Build.VERSION.SDK_INT >= 21) {
CookieManager.getInstance().setAcceptThirdPartyCookies(webview, true);
} else {
CookieManager.getInstance().setAcceptCookie(true);
}
webview.setWebChromeClient(new WebChromeClient() {
#Override
public boolean onCreateWindow(WebView view, boolean isDialog,
boolean isUserGesture, Message resultMsg) {
WebView newWebView = new WebView(getApplicationContext());
newWebView.getSettings().setJavaScriptEnabled(true);
newWebView.getSettings().setSupportZoom(true);
newWebView.getSettings().setBuiltInZoomControls(true);
newWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
newWebView.getSettings().setSupportMultipleWindows(true);
view.addView(newWebView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();
newWebView.setWebChromeClient(new WebChromeClient() {
#Override
public void onPageFinished(WebView view, String url) {
Toast.makeText(getApplicationContext(),"URL"+url,Toast.LENGTH_SHORT);
}
});
newWebView.loadUrl(url);
return true;
}
});
`

Android WebView doesnt load certain website

mWebView = (WebView) findViewById(R.id.webview_m);
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
mWebView.loadUrl(url);
above code work fine when loading website like :
google.com
html5test.com
blogspot
and other normal website, but when i try to load url like:
http://sipp.pn-sanggau.go.id/
http://sipp.pn-bandung.go.id/
it doesnt work (not load in my activity), why does this happen?
Add below lines in your code.
webView.setWebChromeClient(new WebChromeClient() );
webView.getSettings().setPluginState(PluginState.ON);

Android Webview is not showing pop up window

I need in-app browser to hit a URL and authenticate a user,that website pop up a window (on all other browser), but it is not showing pop up on the WebView.
This is my code
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
webView.loadUrl(url);
return true;
}
});
As stated in this issue at Google Code, you should use WebChromeClient within your webview.
WebView wv=new WebView(this);
wv.setWebChromeClient(new WebChromeClient());

How to remove or disable WebView header?

I'm trying to remove the webview header, I've tried a number of possible solutions but to no avail.
One of my attempts:
android:theme="#android:style/Theme.NoTitleBar"
I'm loading the webview using this code:
setContentView(R.layout.activity_websitenew1);
WebView myWebView = (WebView) findViewById(R.id.webView1);
myWebView.loadUrl("http://www.domain.com");
myWebView .setWebViewClient(new WebViewClient());
myWebView.getSettings().setJavaScriptEnabled(true);
What is happening in your case is that the URL is being handled by Android which is choosing the handler for you. This handler is the system's browser application. What you want is for control to stay within your app.
You can do this in code as follows:
WebView myWebView = (WebView) findViewById(R.id.webView1);
myWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadUrl("http://www.domain.com");
See http://developer.android.com/reference/android/webkit/WebViewClient.html#shouldOverrideUrlLoading(android.webkit.WebView,%20java.lang.String) for details.

Click hyperlink on WebView launch other browser app

I use below code to load URLPath in WebView:
WebView webView = (WebView)findViewById(R.id.webview);
String myURL = URLPath;
WebSettings websettings = webView.getSettings();
websettings.setSupportZoom(true);
websettings.setBuiltInZoomControls(true);
websettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(myURL);
The url page contain hyperlink.
I want to launch other browser app(such as chrome) while click hyperlink.
How can I do it?
Use this code
webView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
if(url.equals("http:\\your.url")
view.loadUrl(url);
else
// Do something here to open link in google chrome or some external browser
return true;
}
});

Categories

Resources