0

when the url is https the web views works fine but as soon as it changed to http it opens default browser. here is my code package com.a404gameproductions.insomniax;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class MainActivity extends AppCompatActivity
{
    private WebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mWebView = (WebView) findViewById(R.id.Insomniax_WebView);
        mWebView.loadUrl("https://insomniax.biz");
        mWebView = (WebView) findViewById(R.id.Insomniax_WebView);
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
    }


}

2 Answers2

1

Add this 2 lines in your code -

mWebView.setWebChromeClient(new WebChromeClient()); 

mWebView.setWebViewClient(new WebViewClient());

Nachiket
  • 159
  • 1
  • 8
0

Usually, the default web browser opens and loads the destination URL. However, you open your links on your WebView by adding these lines.

mWebView = (WebView) findViewById(R.id.Insomniax_WebView);
mWebView.setWebViewClient(new WebViewClient());
Nayan
  • 287
  • 3
  • 18