I am trying to load this popular podcast in an Android WebView:
http://www.stitcher.com/podcast/entrepreneuronfirecom/entrepreneur-on-fire-tim-ferriss-other-incredible-entrepreneurs
And this is how I render it:
public class PodcastsActivity extends BaseActivity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
WebView webview = new WebView(this);
webview.getSettings().setAppCacheEnabled(false);
webview.getSettings().setJavaScriptEnabled(true);
webview.setInitialScale(100);
webview.setWebViewClient(new WebViewClient());
setContentView(webview);
webview.loadUrl("http://www.stitcher.com/podcast/entrepreneuronfirecom/entrepreneur-on-fire-tim-ferriss-other-incredible-entrepreneurs");
And in my manifest I have the activity defined like this:
<activity
android:name="PodcastsActivity"
android:label="Podcasts"
android:hardwareAccelerated="true"/>
But it renders like this:
Is there an extra setting that needs to be set? Or something I am missing?
Thanks!
I hope you have looked at other answers. Some of the things you may try are:
1) From webview not loading correctly in application question, you may try and enable java script before loading the URL:
webview.setInitialScale(1);
webview.getSettings().setAppCacheEnabled(false);
webview.getSettings().setJavaScriptEnabled(true);
2) As per Android webview not rendering html content correctly question, if your target is higher than 2.3.3 try adding this in your manifest file.
android:hardwareAccelerated="true"
Update
3) Also check that you have following permission in manifest as direct child to <manifest> tag:
<uses-permission android:name="android.permission.INTERNET" />
Unable to load webpage using WebView in Android
4) You can try shouldOverrideUrlLoading() method as stated here.
Update 2:
As you said that it displays correctly on your browser, there is another possibility of using the above method in case when a certain link is clicked within the app, it opens the default browser. I'm not sure if you would want this but it is a possibility. Something as follows:
webview.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
});
webview.loadUrl("http://www.stitcher.com/podcast/entrepreneuronfirecom/entrepreneur-on-fire-tim-ferriss-other-incredible-entrepreneurs");
Source: WebView link click open default browser
Hope this helps.
Related
I have a problem with showing simple google.com in my WebView.
Tried this on few emulators and 2 phones, all the same, something is wrong with my code.
1. Issue
First screen shows normally google's asking user to accept their legal stuff (1st image).
After accepting it moves to google's main page. But only lower part (Country, settings, adds, about etc.) is shown (2nd image). There is no Google logo, no search bar and buttons and no stuff from the upper display (like GMAIL, GRAPHICS, ACCOUNT and so on).
1ST SCREEN OF GOOGLE.COM
INCORRECTLY SHOWN GOOGLE PAGE
2. Code
I added permission in Manifest.
Trying to solve the issue I stackoverflowed below two lines and added to Manifest, but to no avail:
android:hardwareAccelerated="true"
android:usesCleartextTraffic="true"
**
3. My java code is below:**
(each of the settings I tried to comment out and then one by one uncomment, but still no result).
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = findViewById(R.id.webView);
WebSettings settings = webView.getSettings();
settings.setDomStorageEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
webView.loadUrl("http://www.google.com");
}
}
Could someone please check this is tell me what I've done wrong here?
Stupid thing, should not have done this late into the night.
The problem was only with layout, rest of the page was out of screen.
Needed only to match the WebView to constraints.
I have a WebView in my app with javascript enabled:
textView=(TextView) findViewById(R.id.output);
webView=(WebView) findViewById(R.id.browser_main);
//Tried with those settings,nothing changed
/*webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);*/
webView.addJavascriptInterface(new JSInterface(this), "interface");
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url) {
webView.loadUrl("javascript:window.interface.receiveRaw(document.getElementsByTagName('html')[0].innerHTML);");
}
});
The URL I load returns just some text that's being updated by javascript with setTimeout();. However, after some lines of text WebView stops rendering the page. If I tap the screen the full page with the full text is shown.
For example, if the output of the page is
"Hello\nStack\nOverflow\nHow\nAre\nYou?"
I've got this when I start the app:
Hello
Stack
If I tap on the screen, the full text gets shown:
Hello
Stack
Overflow
How
Are
You?
The problem is that i need the full output when the app starts.
Is there any setting i can change?
May WebChromeClient solve the problem?
I am using WebView on my application.
the WebView contains a web site with link.
When I am clicking on the link, it is open the link on the application(By webView).
How can I open the link with the browser?
Thank you!
Try something like this
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
or if you need to override Webview link click use this
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
This should do the trick
Yo guys, this is bugging me and I can't find a fix for it,
I have a simple activity to launch a WebView and display a HTML file
public class HelpViewer extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.help_page_layout);
WebView browser = (WebView) findViewById(R.id.help_page_webview);
browser.loadUrl("file:///android_asset/help.html/");
}}
The help_page_layout is your standard WebView resting in a LinearLayout - Not problems there.
The help.html is sitting under the /res/raw/ directory. From what I have see online, there shouldn't be a problem here either.
But when the WebView goes to load, it just tells me that the WebPage was not available because help.html couldn't be found.
What am I doing wrong?
This question suggests the file should be in /assets rather than /res/raw. You also have a trailing slash on the end of your URL.
I've set set files to localhost an set the href links for the epub files ..
more-utopia <br>
and I've try to browse from my custom web view .. but when I click to download the link , it appears no download .. and open the file in the browser with custom web view.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView web = (WebView) findViewById(R.id.webview);
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("http://10.0.2.2/epub");
web.setWebViewClient(new myWebView());
}
class myWebView extends WebViewClient{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
url = "http://10.0.2.2/epub/";
view.loadUrl(url);
return true;
}
}
What I want to do is to download the files and want to set path the download location to user selected location .
Any helpful tips are humbly welcome.
Your code is set up to prevent people from downloading anything. Every time they click the link, you have them load the original Web page again. Try using setDownloadListener() on your WebView instead. Or, change your shouldOverrideUrlLoading() to do what your question says you want it to do.