Answer the question
In order to leave comments, you need to log in
How to prevent a WebView from opening a browser when a link is clicked?
Hello I am new to programming and just started to develop an android app so I need help with setting up the app on webview.
How to prevent opening links in a third-party browser?
Below is my MainActivity code:
package com.example.app;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class MainActivity extends Activity {
private WebView mWebView;
@Override
@SuppressLint("SetJavaScriptEnabled")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.setWebViewClient(new MyWebViewClient());
// REMOTE RESOURCE
// mWebView.loadUrl("");
// LOCAL RESOURCE
mWebView.loadUrl("file:///android_asset/index.html");
}
@Override
public void onBackPressed() {
if(mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
}
Answer the question
In order to leave comments, you need to log in
May help:
How to prevent WebView from opening a browser when clicking on a link?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question