Webview always asking where I want to open the url

Asked

Viewed 410 times

1

My Web View every time I test on my mobile phone is asking me how I want to open the url, but I need it to open in webview. Well the code is this :

Java activity.

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class ConectActivity extends Activity {

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

        String url = "http://google.com";
        WebView wv=(WebView) findViewById(R.id.webView);
        WebSettings ws = wv.getSettings();
        ws.setJavaScriptEnabled(true);
        ws.setSupportZoom(true);
        wv.loadUrl("https://google.com");


    }
}

Activity of the layout

<WebView
        android:id="@+id/webView"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </WebView>

And in the manifest this :

<uses-permission android:name="android.permission.INTERNET"/>

Would someone please know how to fix ?

1 answer

2


Before calling the method loadUrl() indicate to webView which client to use:

String url = "http://google.com";
WebView wv=(WebView) findViewById(R.id.webView);
WebSettings ws = wv.getSettings();
ws.setJavaScriptEnabled(true);
ws.setSupportZoom(true);

wv.setWebViewClient(new WebViewClient());

wv.loadUrl("https://google.com");
  • It worked perfect, thank you XD

Browser other questions tagged

You are not signed in. Login or sign up in order to post.