Android Webview not loading linkedin page - android

I am trying to load linkedin page in webview but i can only see linkedin logo but i tried loading facebook and it facebook successfully. Here is my code:
public class WebViewActivity extends Activity {
WebView web;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
web = (WebView) findViewById(R.id.webview01);
web.setWebViewClient(new myWebClient());
web.loadUrl("https://www.linkedin.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) {
view.loadUrl(url);
return true;
}
}
}
Can anybody help me out. Thanks in advance.

You need to enable javascript in your WebView like this:-
web.getSettings().setJavaScriptEnabled(true);

Related

Open new tabs on default browser when using webview

I want to tell you I never try android development before, and this is the first time I'm doing an android app I build a website using ASP.NET and I want to run that site within the android app web view.
So followed a few tutorials and I did so far.
Here when I redirect to some external sites In my site, I open them on another new tab on the browser, here I want to open it on the mobile phone's default browser instead of the opening inside the web view.
need a help to doing that.
This is my app MainActivity code.
public class MainActivity extends AppCompatActivity {
WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView=findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://www.mycustom:5500/test/");
WebSettings websettings = webView.getSettings();
websettings.setJavaScriptEnabled(true);
}
private class MyWebView extends WebViewClient {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
return super.shouldOverrideUrlLoading(view, request);
}
}
#Override
public void onBackPressed() {
if (webView.isFocused() && webView.canGoBack()){
webView.goBack();
}else{
super.onBackPressed();
}
}
}

News link in webview

I am new in android and I am displaying a news link in a webview. News link is displaying properly but video in news link is not playing.
Link is :
http://aajtak.intoday.in/livetv.html
My code is:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
web = (WebView) findViewById(R.id.webview01);
web.setWebViewClient(new myWebClient());
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
web.getSettings().setPluginState(PluginState.ON);
web.loadUrl("http://aajtak.intoday.in/karyakram/video/so-sorry-episode-of-10th-august-2016-on-delhi-aam-admi-party-mla-and-rajnath-singh-najeeb-jung-1-882177.html");
}
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;
}
}
To support video in webview, you need to have hardware acceleration turned on, and set a WebChromeClient.
For full screen support, implementations of onShowCustomView(View, WebChromeClient.CustomViewCallback) and onHideCustomView() are required.
Used this, but now a days onShowCustomView() is deprecated.
from
YouTube Video not playing in WebView - Android
Try adding this code :
webView.setWebChromeClient(new WebChromeClient());

web view url goes to browser .how to do avoid and open in same web view?

here my code...am already implemented WebViewClient concept.it works well in web view..In my App have content saring via fb,twitter,g+,,,fb also login and open in webview...but when am click share to fb icon in my app after that all process will work on browser..but i want all process in webview only...
oncreate
webView = (WebView) findViewById(R.id.webView1);
webView.setClickable(true);
webView.setFocusableInTouchMode(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new myWebClient());
if (Build.VERSION.SDK_INT < 8) {
...
} else {
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
}
webView.loadUrl("www.example.com.");
WebViewClient
public class myWebClient extends WebViewClient {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
public void onLoadResource (WebView view, String url) {
}
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
webView.loadUrl("file:///android_asset/myerrorpage.html");
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
progress.setVisibility(View.VISIBLE);
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progress.setVisibility(View.GONE);
}
}
You must override your shouldOverrideUrlLoading() method in WebViewClient class and following code
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.example.com")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
Go through the documentation for more information.
Use a if clause in your shouldOverrideUrlLoading method that returns false;
Example from Building web apps in web views
if (Uri.parse(url).getHost().equals("www.example.com")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}

ProgressBar in android webview not stop spinning

i'm creating a android webview app. Im facing a problem with progress bar. The progress bar is completely and fully implemented and keeps spinning. but it doesn't stop spinning even after the page loads completely. what should i do?
main activity layout::::
<ProgressBar android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
mainActivity.java:::
public class MainActivity extends ActionBarActivity {
WebView web;
ProgressBar progressBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
web = (WebView) findViewById(R.id.webView1);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setBuiltInZoomControls(true);
web.loadUrl("http://google.com");
web.setWebViewClient(new WebViewClient()); }
public class webclient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
}
Where is the error here? please help me im also having problem with adview. here
You've created a custom WebViewClient class but you aren't using it.
Change web.setWebViewClient(new WebViewClient());
to web.setWebViewClient(new webclient());
Change these two methods.
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
progressBar.dismiss();
}
#Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
}
Change web.setWebViewClient(new WebViewClient());
to web.setWebViewClient(new webclient());

webview links opens into a default browser

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

Categories

Resources