WebView not Working Properly - android

I made a url to open through webview and everything worked fine for me except some buttons of the webpage it doesn't respond anything
public class browse extends AppCompatActivity {
WebView appwebview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_browse);
String profileID= getIntent().getStringExtra("inputtext");
Toast.makeText(getApplicationContext(),profileID,Toast.LENGTH_SHORT).show();
appwebview=(WebView) findViewById(R.id.webview);
WebSettings webSettings= appwebview.getSettings();
webSettings.getJavaScriptEnabled();
appwebview.loadUrl("https://statsroyale.com/profile/"+profileID);
appwebview.setWebViewClient(new WebViewClient());
}
#Override
public void onBackPressed() {
if(appwebview.canGoBack())
appwebview.goBack();
else
super.onBackPressed();
}
}
the intent passes text of textfield from MainActivity and depending on that text i used to show profile.

Probably you forgot to activate Javascript in the WebView.
Please try this:
webSettings.setJavaScriptEnabled(true);
instead of:
webSettings.getJavaScriptEnabled();
A couple of other settings could help:
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setAllowFileAccess(true);
settings.setAllowContentAccess(true);
settings.setAllowFileAccessFromFileURLs(true);
settings.setAllowUniversalAccessFromFileURLs(true);
settings.setDomStorageEnabled(true);

Add this code to appwebview when it finishes loading as sometimes javascript interaction does not work properly.
appwebview.requestFocus();

Related

Specific website is not loading in android web view

I am trying to load http://www.bing.com or https://www.bing.com in web view but it is not loading. When I debug I found that the onPageFinished() callback is executed and the web view is still blank.
I have tried with other websites such as http://www.google.com it works fine.
Here is my code
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
WebView webView = findViewById(R.id.web_view);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setDomStorageEnabled(true);
webView.setWebViewClient(new WebViewController());
webView.loadUrl("http://www.bing.com");
}
public class WebViewController extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
In the logs I'm getting the following message when I'm trying to load bing website
2020-04-10 17:41:31.981 6044-6044/com.mawinbet.android I/chromium: [INFO:CONSOLE(0)] "The resource http://www.bing.com/rb/2U/cj,nj/6BsKE-ZQeKe0vHb0vclH0k01aag.js?bu=BUBKDlVY was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: (0)
Can you please tell me how to solve this problem.

PayuMoney Payment Gateway Not Working in Android Web View for Opencart

I am using android web view for opencart website. Everything is working except payment gateway for payumoney. After clicking confirm order, the app is redirecting to gateway and once someone select other sub options, like netbanking, or wallet or debit card etc, its showing blank page.
The code is listed below:
enter protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
mWebView = findViewById(R.id.activity_main_webview);
mWebView.setWebViewClient(new WebViewClient());
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true); // replace settings with what matches your code
//REMOTE RESOURCE
mWebView.loadUrl("http://example.com");
mWebView.setWebViewClient(new MyWebViewClient());
// LOCAL RESOURCE
// mWebView.loadUrl("file:///android_asset/index.html");
}
#Override
public void onBackPressed() {
if(mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
Kindly tell what is missing.

Android Studio - Video Volume Low

I have taken a web page which has several videos that show in modals and put it in a WebView. When I open this page on my laptop I get full volume. When I launch the app and try to view the video I don't see video controls and the sound on the tablet is turned all the way up, yet it is very quiet. What am I missing here?
The WebView
public class MainActivity extends AppCompatActivity {
private WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView=findViewById(R.id.webviewid);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("file:///android_asset/index.html");
}
}
Turn JavaScript On for the WebView.
mWebView.getSettings().setJavaScriptEnabled(true);

Opening a webpage in webview

Hi in my application I have to have open a webview and show the contents. For other pages it works well, but facing issue on only this page Link
whenever I open this in webview nothing pops up, and i can only see a black page and nothing else.
Here is my code.
mWebView = (WebView)rootView.findViewById(R.id.webview_livechat);
setUpWebViewDefaults(mWebView);
// mWebView.setWebChromeClient(new WebChromeClient());
mWebView.loadUrl("http://www.zong.com.pk/livechat/chat.php?a=acb8c");
return rootView;
}
#SuppressLint("SetJavaScriptEnabled")
#TargetApi(19)
private void setUpWebViewDefaults(WebView webView) {
WebSettings settings = webView.getSettings();
mWebView.setWebViewClient(new WebViewClient());
settings.setJavaScriptEnabled(true);
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
settings.setBuiltInZoomControls(true);
settings.setPluginState(PluginState.ON);
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
settings.setDisplayZoomControls(false);
mWebView.setWebViewClient(new WebViewClient());
}
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
mWebView.setWebViewClient(new WebViewClient());
}
}
I have tested your code in a simple activity with a WebView and it seems to be working on an emulator with Android-Version 4.4.4 (API 19). I had just to wait a few seconds.

How to enable Addressbar in Android WebView?

I´m actually using a WebView in my Application and it works pretty good.
Now I´d like to be able to change the actual URL, just like that Addressbar in the Android Stock browser, where you can see the URL and where you simply can change it.
How can I enable this bar? Or do I have to implement it myself?!
Thanks!
My Code looks like:
private void setupWebView() {
webview = new WebView(this);
webview.setWebViewClient(new MyWebViewClient());
WebSettings webSettings = webview.getSettings();
webSettings.setUserAgentString("foo");
webSettings.setJavaScriptEnabled(true);
webSettings.setAppCacheEnabled(false);
webSettings.setBuiltInZoomControls(true);
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
MyActivity.this.setProgress(progress * 100);
}
});
}
Impossible:
The WebView class is an extension of Android's View class that allows
you to display web pages as a part of your activity layout. It does
not include any features of a fully developed web browser, such as
navigation controls or an address bar. All that WebView does, by
default, is show a web page.
http://developer.android.com/guide/webapps/webview.html
If you want to change URL by code:
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.example.com");

Categories

Resources