2

I want to open the following link in WebView

https://tickets.musiconelive.com/admin/SACValidateBarcode.asp

I am using following code to do that

web=(WebView)findViewById(R.id.web);
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("https://tickets.musiconelive.com/admin/SACValidateBarcode.asp");

but it's not opening in WebView and instead is opening in the browser.

How can I fix this problem?

Toto
  • 89,455
  • 62
  • 89
  • 125
surendra
  • 2,217
  • 7
  • 34
  • 42

4 Answers4

10

may this helps you

        WebSettings mWebSettings;

        WebView mWebView = (WebView)findViewById(R.id.services_detail_magnified_image);
        mWebView.getSettings().setBuiltInZoomControls(true);
        mWebView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
        mWebView.setBackgroundColor(Color.TRANSPARENT);
        mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_INSET);

        mWebView.loadUrl(StaticURL.uChangePassword);
        mWebView.setWebViewClient(new MyWebViewClient());

private 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;
        } 
    }
Mohammed Azharuddin Shaikh
  • 41,633
  • 14
  • 96
  • 115
  • helloo this code is gud for only single webview.i want to add the wegview in in listview.is it posible?wanna play gif in webview..you can also see the link of my questions. – Google Oct 10 '12 at 07:03
  • you can see the link http://stackoverflow.com/questions/12159336/gif-not-animated-in-custom-listview – Google Oct 10 '12 at 07:11
  • 1
    for me worked like this: mWebView.setWebViewClient(new WebViewClient()); so there was no need to create an extra class – pawliux Nov 04 '17 at 23:56
3

i think this will help you.

 package com.adySol;
 import android.app.Activity;
 import android.os.Bundle;
 import android.webkit.WebSettings.PluginState;
 import android.webkit.WebView;

 public class adySol extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


 String url ="http://tickets.musiconelive.com/admin/SACValidateBarcode.asp";
 WebView wv=(WebView) findViewById(R.id.webView1);
 wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setPluginState(PluginState.ON);
    wv.getSettings().setAllowFileAccess(true); 
 wv.loadUrl(url);
    }
  }   

Main.xml::

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
>
 <WebView android:id="@+id/webView1" android:layout_width="match_parent"  android:layout_height="match_parent"></WebView>

</LinearLayout>  

Manifest permission :

 <uses-permission android:name="android.permission.INTERNET"></uses-permission>
Nikunj Patel
  • 21,853
  • 23
  • 89
  • 133
0

You need to set WebViewClient()

This is example in kotlin
webview.apply {
            loadUrl("https://www.google.com/")
            webViewClient = WebViewClient()
        }

As per android documentation public void setWebViewClient (WebViewClient client) Sets the WebViewClient that will receive various notifications and requests. This will replace the current handler.

-1
    webView=findViewById(R.id.webView);        
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR)
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_INSET);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);
    webView.getSettings().setAllowFileAccess(true);
    webView.setWebViewClient(MyWebViewClient());
    webView.loadUrl("https://google.com/");



class MyWebViewClient extends WebViewClient() {
    @override
    boolean  shouldOverrideUrlLoading(WebView view , WebResourceRequest request) {
        return super.shouldOverrideUrlLoading(view, request)
    }
}
mayank
  • 1