surendra
surendra

Reputation: 2267

Not opening in WebView but in browser

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?

Upvotes: 2

Views: 11202

Answers (4)

Sujit Acharya
Sujit Acharya

Reputation: 31

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.

Upvotes: 0

mayank
mayank

Reputation: 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)
    }
}

Upvotes: -1

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

Upvotes: 10

Nikunj Patel
Nikunj Patel

Reputation: 22066

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>

Upvotes: 3

Related Questions