X
X
xaiponews2020-10-05 23:00:43
Android
xaiponews, 2020-10-05 23:00:43

How to open link from WebView in new activity with WebView?

Two days of searching gave such a result, I feel that I'm close. Help fix the code

public class MainActivity extends AppCompatActivity {
    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        webView = findViewById(R.id.webhome);
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webView.loadUrl("https://www.google.com");
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest URL) {
                Intent intent;
                switch (view.getUrl()) {
                    case R.id.webhome:
                        intent = new Intent("info.android.intent.action.URL");
                        intent.putExtra("url", URL.getUrl().toString());
                        startActivity(intent);
                        return super.shouldOverrideUrlLoading(view, URL);
                }
                return false;
            }
        });
    }

Throws error: incompatible types: int cannot be converted to String case R.id.webhome:
What should case R.id.webhome be replaced with?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2020-10-06
@zagayevskiy

Obviously, on some line containing url.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question