i have to use webview to show asp.net rdlc report using http url.
now i can download PDF file in web view show option in bellow image
You should create WebViewClient and set it to your webview.
every time you click a link WebViewClient's shouldOverrideUrlLoading method will be called.
You can get the PDF url, now call async task and download the file in device.
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading (WebView view, String url) {
if (url.endsWith(".pdf")) {
// call Asynctask and download pdf file
return true;
}
return false;
}
});
Related
so I just started with Android programming and I am trying to make a little app using WebView. There is a url that redirects you to a pdf, I know WebView does not render pdf. So I want to use intent and display the pdf in Google Docs. However, the pdf address is randomly generated so I cant link it with
WebView.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdfURL);
How can I send an intent to Google Docs without using the exact pdf address?
I don't know what "randomly generated" means.
But the first thing that comes to my mind is to set a WebViewClient and override shouldOverrideUrlLoading:
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.endsWith(".pdf") == true) {
view.loadUrl("http://docs.google.com/gview?embedded=true&url=" + url);
return true;
}
return false;
}
});
Some more info in this thread.
I'm using a standard WebView implementation, and overriding the shouldOverrideUrlLoading method to catch request to external domains. The call is being captured on all of my tested versions (15-22); however,on 15-18, the WebView navigates to the requested URL before shouldOverrideUrlLoading is called to execute the External Browser request.
Example:
SDK >= 19
WebView -> Load URL -> shouldOverrideUrlLoading(TRUE) -> URL loaded in External Browser and WebView's state is retained.
SDK <= 18
WebView -> Load URL -> URL loaded in WebView -> shouldOverrideUrlLoading(TRUE) -> URL loaded in External Browser and WebView's state is lost.
WebView Override Code:
private void webViewClient() {
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith(BASE_URL)) {
return false;
} else {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
return true;
}
}
});
}
One possible cause:
This behavior makes sense if the URL being loaded is "invalid" (like something other than "http://whatever.com/"), and is somehow also a "redirect".
If the invalid url being loaded is a "redirect"... >=19 will not call the shouldOverrideUrlLoading at all.
If the FINAL URL is valid, however, and doesn't start with BASE_URL, it would call shouldOverrideUrlLoading, then launch the new window, as your code says.
That said, I have no idea how you would get an invalid URL to be a redirect -- so without more information about the URLs (BASE_URL and the URL being requested), it's impossible to say.
Read more about the differences between the WebView in 19+... big changes were made at that time:
https://developer.android.com/guide/webapps/migrating.html
I want to create android application which will open url in same application as like facebook application without any browser.
I tried using WebView but it opens the url in browser.
You have to set up a webViewClient for your webView.
Sample code :
this.mWebView.setWebViewClient(new WebViewClient()
{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
});
I am passing a url into my application and calling loadUrl on a CordovaWebView. Anytime I try with an external URL it opens the link in an external browser application. I need it to remain in my application.
myCordovaWebView.loadUrl("http://google.com");
myCordovaWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}});
myCordovaWebView.loadUrl("http://google.com");
I am working on an Android project, and my task is to open a url in an embedded webview. Here is the code. When a button is clicked I open the url as follows:
yookosBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
linearLayout.setVisibility(View.GONE);
webview.setVisibility(View.VISIBLE);
webview.loadUrl("https://www.google.com.pk/");
}
});
1: When i open the google.com it is perfectly opened in embedded webview:
But when I replace the link with "http://videoshare.loveworldapis.com/commentredirect.php" url, the link is opened in full screen instead of embedded portion of webview as shown below:
Can you tell me what modification should I do to open the second website into embedded webview instead of full screen.
The WebView, by default, will open successive URLs by firing an intent, and opening the browser. To disable it so all URLs load in the WebView do this:
webView.setWebViewClient(new WebViewClient()
{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
return false;
}
});
I suspect your web site load involves an HTTP redirect, and that redirect is causing the browser to open.