Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView not Working Properly

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.

like image 379
Jasbin Karki Avatar asked Sep 05 '25 03:09

Jasbin Karki


1 Answers

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);
like image 138
gil.fernandes Avatar answered Sep 07 '25 21:09

gil.fernandes