Webview showing a white blank page - android

I am using webview for showing Flipkart website in my application.
Everything is working fine as needed except one thing:
when I click on BuyNow button, select variant view gets visible.
This view comes for 1 sec and then show the white blank page.
Is there any setting i need to enable in webview to show this types of view?
I had already gone through many questions on Stackoverflow but nothing helped me.
I tried setting webchromeclient and below methods on webview with no success.
shopping_webview.getSettings().setAllowFileAccess(true);
shopping_webview.getSettings().setAllowContentAccess(true);
shopping_webview.getSettings().setAllowFileAccessFromFileURLs(true);
shopping_webview.getSettings().setAllowUniversalAccessFromFileURLs(true);
shopping_webview.getSettings().setDomStorageEnabled(true);
shopping_webview.getSettings().setUseWideViewPort(true);
shopping_webview.getSettings().setLoadWithOverviewMode(true);
shopping_webview.getSettings().setLoadsImagesAutomatically(true);
shopping_webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
shopping_webview.getSettings().setSupportMultipleWindows(true);
shopping_webview.getSettings().setBuiltInZoomControls(true);
shopping_webview.getSettings().setDisplayZoomControls(false);
shopping_webview.getSettings().setJavaScriptEnabled(true);

webviewLink.getSettings().setLoadsImagesAutomatically(true);
webviewLink.getSettings().setJavaScriptEnabled(true);
webviewLink.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webviewLink.loadUrl(postlink);
webviewLink.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO show you progress image
progressBar.setVisibility(View.VISIBLE);
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, String url) {
// TODO hide your progress image
progressBar.setVisibility(View.GONE);
super.onPageFinished(view, url);
}
});
load the Url with this way it's work for me in the same app..

WebView webView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webView.setWebViewClient(new MyWebViewClient());
webView.loadUrl(_URL);
}
private class MyWebViewClient extends WebViewClient{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getApplicationContext(), "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
}

Related

Why can't I get onPageStarted, onReceivedError, or onPageFinished to ever call with Android WebView?

I want to be able to recognize when an error occurs and tell show a toast message with the error but I can never get them to call.
I also want to be able to tell when the webview starts navigating to a url and detect which url it's going to.
Unfortunately it just seems to ignore everything and I have no idea how to start a function or method or anything once this occurs.I don't really care how I go about determining when a page starts loading or an error occurs I just need a way that works.
public class MainActivity extends AppCompatActivity {
private WebView myWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
myWebView.setWebChromeClient(new WebChromeClient()
{
private boolean error;
public void onPageStarted(WebView view, String url, Bitmap favicon) {
onPageStarted(view, url, favicon);
Toast.makeText(getApplicationContext(), "page started:" + url, Toast.LENGTH_SHORT).show();
error = false;
}
public void onReceivedError( WebView view, int errorCode, String description, String failingUrl) {
error = true;
System.out.println("description error" + description);
view.setVisibility( View.GONE );
Toast.makeText(getApplicationContext(), "error:" + description, Toast.LENGTH_SHORT).show();
}
public void onPageFinished(WebView view, String url) {
if (!error) {
view.setVisibility( View.VISIBLE );
}
error = false;
Toast.makeText(getApplicationContext(), "page finished" + url, Toast.LENGTH_SHORT).show();
}
}
);
myWebView.setBackgroundColor(0);
WebSettings webSettings = myWebView.getSettings();
webSettings.setDefaultTextEncodingName("utf-8");
webSettings.setJavaScriptEnabled(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setAllowFileAccess(true);
// Other webview settings
myWebView.addJavascriptInterface(new MyJavascriptInterface(this), "Android");
myWebView.loadUrl("https://example.com/");
}
}
The onPageStarted(), onPageFinished(), and onReceivedError() methods are not defined in the WebChromeClient class. They're members of WebViewClient. You subclassed the wrong one.
If you add the #Override annotation above each method, your IDE should yell at you that those methods don't override anything in the super class, which is why that annotation is useful.
Simply move those overrides to the WebViewClient instance.
myWebView.setWebViewClient(new WebViewClient() {
private boolean error;
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
...
}
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
...
}
#Override
public void onPageFinished(WebView view, String url) {
...
}
}
);
myWebView.setWebChromeClient(new WebChromeClient());

Android WebView open app and load link

I have users that receive a link to my website via email.(EG. example.com/special folder/file) When they click on the link it prompts them to open my app as it should. However I am unable to figure out how to load that link they clicked in my app. (Each user is sent a specific page tailored to them) From the research I have done all the examples are loading the website using:
String url ="http://example.com";
myview.loadUrl(url);
Again I am trying to load the orginal link they clicked on. Not the static URL.
If anyone can point me in the right direction or better yet provide a sample of how i would achieve this it would be much appreciated.
Update1
To put it simply It works like youtube. If you were sent a link via email to a youtube video it would prompt you to use the youtube app. Then load the video you were sent. All i need is my app to load the webpage the user was sent
Proper way of loading webview using ProgressDialog for user feedback.
private ProgressDialog dialog = new ProgressDialog(WebActivity.this);
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView1);
String url="http://www.google.com";
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url) {
if (dialog.isShowing()) {
dialog.dismiss();
}
}
});
dialog.setMessage("Loading..Please wait.");
dialog.setCanceledOnTouchOutside(false);
dialog.show();
webView.loadUrl(url);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
}
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
webView = (WebView) findViewById(R.id.WebView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
showProgress();
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
hideProgress();
}
#Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
}
});
webView.loadUrl("http://google.com");

WebView videos not playing on samsung devices

I have a simple webview ,nothing complex
URL = getIntent().getExtras().getString(FinalVariables.LOAD_URL);
mWebView =(WebView) findViewById(R.id.mywebview);
progressBar = (ProgressBar)findViewById(R.id.progressbar);
if(!TextUtils.isEmpty(URL))
mWebView.loadUrl(URL);
mWebView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url);
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
});
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
But for some reason if the opened page has a video in it, it won't get played
this is what I am seeing now.But when I run this same code on sony device,no problems there.I tried enabling the android:hardwareAccelerated="true" in AndroidManifest.xml but didn't work.Any help is appreciated.
I found a solution for this and was quite simple.Adding a single line on shouldOverrideUrlLoading fixed the problem ie,
mWebView.setWebChromeClient(new WebChromeClient());
Hope this will help someone.

Web view not rendering page after onPageFinish() called Showing blank page for some time and renders the page? - Android

I am loading dymanic webpage from my server designed in JQuery and NodeJS inside webview. I kept loading bar inside WebClient onPageStarted() and removed the same in onPageFinished().
But after calling page finish still web page is not rendered and webview showing blank page for some time and then renders the page after few seconds.
The same is working properly with other sites like google, etc.
Is there a way we designed the webpage?
Try this,
WebView webview = (WebView) findViewById(R.id.webView1);
final ProgressDialog pd = ProgressDialog.show(WebPage.this, "",
"Loading...", true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
Toast.makeText(getApplicationContext(), description,
Toast.LENGTH_SHORT).show();
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
pd.show();
}
#Override
public void onPageFinished(WebView view, String url) {
pd.dismiss();
}
});
webview.loadUrl(yourURL);
}

Android webview app shows "complete the action using" popups

I am working with android app for the web view. It loads the webpage but i cant make more actions on the page using my app. when I am choosing a hyperlink from the page it shows a popup"complete the action using chrome,opera etc.." how can I use this without such browsers..I nedd to browse web contents using my app. how it possible??
I used the code
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");
please help me since I am new to android and thank you.
wv.loadUrl(url);
wv.setWebViewClient(new MyWebViewClient());
Your WebViewCLient class would look like this:
class MyWebViewClient extends WebViewClient {
#Override
// show the web page in webview but not in web browser
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
webProg.setVisibility(View.GONE);
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
}
}

Categories

Resources