I am trying to open .pptx file n android webview with google docs its throwing error unable to load but its able to load .ppt type urls.any help is appreciated
try this
WebView webview = (WebView)findViewById(R.id.containWebView);
webview.setWebViewClient(new AppWebViewClients());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setUseWideViewPort(true);
webview.loadUrl("http://docs.google.com/gview?embedded=true&url="
+ "YOUR_DOC_URL_HERE");
public class AppWebViewClients extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
}
}
Related
I am trying to load pdf file from link in Android Marshmallow. It always shows blank screen while the code works fine with lower versions than 6.0. Please help.
Thanks
Below is code which i am using
webView = (WebView)findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
webView.loadUrl ("http://drive.google.com/viewerng/viewer?embedded=true&url="+url);
return super.shouldOverrideUrlLoading(view, url);
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
// showProgress(LoadPageByUrlActivity.this,"Please wait...");
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, String url)
{
super.onPageFinished(view, url);
// stopProgress();
}
});
String url = getIntent().getExtras().getString("url");
if(url.contains("pdf")){
webView.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url="+url);
}else
webView.loadUrl(url);
}
I am trying to open a link using Webview in Android. There are some links embedded into WebView. My problem is webview is not opening any link that does not starts with www. For ex, www.google.com is working but maps.google.com is not.I have also tried to override WebViewClient but it didn't work.
One thing I noticed is by putting Toast to see what url is being called in WebViewClient. It showed perfect for www.google.com but returned nothing for other links. I thing WebViewClient is not getting overriden in that case. What could be the reason. Do I have to call any ethod or some property of webview.
Any help will be appreciated.
menuView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
super.shouldOverrideUrlLoading(view, url);
Toast.makeText(getApplicationContext(), "url:--" + url, Toast.LENGTH_LONG).show();
view.loadUrl(url);
return false;
}
});
Properties that I have already set are :
menuView.setVerticalScrollBarEnabled(false);
menuView.setHorizontalScrollBarEnabled(false);
final WebSettings webSettings = menuView.getSettings();
menuView.getSettings().setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setPluginState(PluginState.ON);
webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
menuView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
menuView.getSettings().setBuiltInZoomControls(true);
// Below required for geolocation
menuView.getSettings().setJavaScriptEnabled(true);
menuView.getSettings().setGeolocationEnabled(true);
webSettings.setGeolocationEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
// in oncreate
webview.setWebChromeClient(new wecrome());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLoadsImagesAutomatically(true);
webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webview.setWebViewClient(new MyBrowser());
webview.getSettings().setPluginState(PluginState.ON);
webview.loadUrl("http://www.example.net/locations/");
//inner class
private class MyBrowser extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
view.addJavascriptInterface(new Object() {
#JavascriptInterface
public void performClick() throws Exception {
Log.d("LOGIN::", "Clicked");
Toast.makeText(googleplus.this, "Login clicked",
Toast.LENGTH_LONG).show();
}
}, "login");
return true;
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
System.out.println("started");
pd.show();
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
pd.dismiss();
System.out.println("ends");
super.onPageFinished(view, url);
}
}
i'm new to android programing.my problem is that in my webview when i click on any link its opening to a new web browser i dont need this i want it to be opened in my app itself.can someone help me??
this is my code
title = extras.getString("title");
url = extras.getString("url");
TextView text=(TextView) findViewById(R.id.textView1);
text.setText(title);
WebView myWebView =(WebView)findViewById(R.id.WebView);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
}
i tried this but my webview is not loading its showing a blank screen
web = (WebView) findViewById(R.id.webview01);
web.setWebViewClient(new myWebClient());
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("http://www.google.com");
public class myWebClient extends WebViewClient
{
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
}
pls help me to display custom Web Page Not Available error page...in webview..i tried many code and when i run the app it shows app has been stopped
You can override onReceivedError callback of WebViewClient to achieve the desired functionality.
Either you can display some dialog to denot your custom message or load the webview with any custom html available locally in your app.
USE this it working fine on my side. May be it will help you
private WebView webviewSites;
String URL="http://www.google.com";
webviewSites = (WebView) findViewById(R.id.webview_sites);
WebSettings webSettings = webviewSites.getSettings();
webSettings.setSupportMultipleWindows(true);
webSettings.setJavaScriptEnabled(true);
webviewSites.setWebViewClient(new myWebClient());
webviewSites.loadUrl(URL);
public class myWebClient extends WebViewClient {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(final WebView view, final String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
// mProgressBar.setVisibility(View.GONE);
Log.i("LOAD_URL", "" + url);
}
l am using webview in my xml, loading html file from asset directory. But clicking on links sometimes launching browser on first click and sometimes not responding even after 5 clicks.
Any help is appreciated.
Thanks
For, this you've to use WebViewClient() to your WebView
WebView web = (WebView)findViewById(R.id.webView1);
.....
..... // Your stuff
.....
web.setWebViewClient(new HelloWebViewClient());
public class HelloWebViewClient extends WebViewClient
{
public HelloWebViewClient()
{
// do nothing
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url)
{
// TODO Auto-generated method stub
super.onPageFinished(view, url);
}
}
just add these lines
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);