Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android webview stay in app

Tags:

I have a webview in my android app, but when someone navigates around the site, it opens in a new window, i want it to stay inside the webview.. is there a way to do this easily? Here is the code in my activity:

super.onCreate(savedInstanceState);     setContentView(R.layout.shop);     WebView webview;     webview = (WebView) findViewById(R.id.webview);     webview.getSettings().setJavaScriptEnabled(true);     webview.loadUrl("http://www.google.co.uk"); 
like image 339
Carla Dessi Avatar asked Nov 24 '12 16:11

Carla Dessi


People also ask

What is alternative of WebView in Android?

Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.

Does PlayStore accept WebView app?

We don't allow apps whose primary purpose is to drive affiliate traffic to a website or provide a webview of a website without permission from the website owner or administrator.

Is Android WebView deprecated?

The Android system webview custom cache file has been deprecated and removed in Android 13. New apps and any app updates will now use the operating system default cache location.


1 Answers

You'll have to create a WebViewClient:

public class myWebViewClient extends WebViewClient {     @Override     public boolean shouldOverrideUrlLoading(WebView view, String url) {         view.loadUrl(url);         return true;     } } 

And then set it to your WebView like this:

webview.setWebViewClient(new myWebViewClient()); 
like image 117
Ahmad Avatar answered Sep 26 '22 00:09

Ahmad