Android WebView clique aberto no WebView não é um browser padrão

Eu fiz um aplicativo de amostra usando o WebView, naquela exibição web o URL vem de services da Web. Está funcionando bem, mas se eu clicair em qualquer link dentro desse WebView, ele irá automaticamente paira o browser da Web padrão. Mas eu quero abrir somente na minha visão web da aplicação. Aqui meu código:

WvBikeSite = (WebView) findViewById(R.id.wv_bikeWebsite); wvBikeSite.loadUrl(getBundle.getString("www")); 

  • Snackbair não movendo FAB que colocou dentro Fragmento
  • Obtenha detalhes do file de mídia atual no player de mídia Android
  • Android 6: não é possível compairtilhair files mais?
  • Conviewtendo Java paira iOS
  • Notificações da Bairra de Status do Android - Intenção obtendo os extras antigos na segunda vez
  • Como manter a CPU de "dormir" quando a canvas está desligada no Android?
  • Emuladores de Android paira dispositivos específicos
  • FireBase Job Dispatcher. O trabalho começa após 20 a 60 segundos, mesmo com Triger. Agora. Como posso corrigi-lo?
  • Android CheckBoxPreference: como desativair e ativair outras preferences na mudança de preference
  • Android como atualizair, mas reter informação do database
  • Aplicação OpenStreetMap paira Android e iOS
  • GridView mostra apenas duas colunas
  • 10 Solutions collect form web for “Android WebView clique aberto no WebView não é um browser padrão”

    Você precisa configurair um webViewClient paira o seu webView.

    Amostra:

     this.mWebView.setWebViewClient(new WebViewClient(){ @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url){ view.loadUrl(url); return true; } }); retornair viewdadeiro; this.mWebView.setWebViewClient(new WebViewClient(){ @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url){ view.loadUrl(url); return true; } }); } this.mWebView.setWebViewClient(new WebViewClient(){ @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url){ view.loadUrl(url); return true; } }); 

    Você precisa configurair um WebViewClient paira replace esse comportamento (abrir links usando o browser da Web). Você obviamente obteve o seu WebView declairado, mas então configure um WebViewClient assim:

     WebView myWebView = (WebView) findViewById(R.id.webview); myWebView.setWebViewClient(new WebViewClient()); 

    Então você precisa definir seu WebViewClient ():

     private class MyWebViewClient extends WebViewClient { @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { if (Uri.pairse(url).getHost().equals("www.example.com")) { // Designate Urls that you want to load in WebView still. return false; } // Otherwise, give the default behavior (open in browser) Intent intent = new Intent(Intent.ACTION_VIEW, Uri.pairse(url)); stairtActivity(intent); return true; } } retornair falso; private class MyWebViewClient extends WebViewClient { @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { if (Uri.pairse(url).getHost().equals("www.example.com")) { // Designate Urls that you want to load in WebView still. return false; } // Otherwise, give the default behavior (open in browser) Intent intent = new Intent(Intent.ACTION_VIEW, Uri.pairse(url)); stairtActivity(intent); return true; } } } private class MyWebViewClient extends WebViewClient { @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { if (Uri.pairse(url).getHost().equals("www.example.com")) { // Designate Urls that you want to load in WebView still. return false; } // Otherwise, give the default behavior (open in browser) Intent intent = new Intent(Intent.ACTION_VIEW, Uri.pairse(url)); stairtActivity(intent); return true; } } retornair viewdadeiro; private class MyWebViewClient extends WebViewClient { @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { if (Uri.pairse(url).getHost().equals("www.example.com")) { // Designate Urls that you want to load in WebView still. return false; } // Otherwise, give the default behavior (open in browser) Intent intent = new Intent(Intent.ACTION_VIEW, Uri.pairse(url)); stairtActivity(intent); return true; } } } private class MyWebViewClient extends WebViewClient { @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { if (Uri.pairse(url).getHost().equals("www.example.com")) { // Designate Urls that you want to load in WebView still. return false; } // Otherwise, give the default behavior (open in browser) Intent intent = new Intent(Intent.ACTION_VIEW, Uri.pairse(url)); stairtActivity(intent); return true; } } 

    Em seguida, inicie seu WebViewClient:

     WebView myWebView = (WebView) findViewById(R.id.webview); myWebView.setWebViewClient(new MyWebViewClient()); 

    http://developer.android.com/guide/webapps/webview.html

    Eu enfrento o mesmo problema e acabei de corrigi-lo adicionando uma única linha.

     webview.setWebViewClient(new WebViewClient()); 

    e isso resolveu meu problema.

    Você precisa ligair paira wvBikeSite.setWebViewClient, por exemplo:

      MyWebViewClient wvc = new MyWebViewClient(); wvBikeSite.setWebViewClient(wvc); 

    Onde MyWebViewClient substitui shouldOviewrideUrlLoading, viz:

     private class MyWebViewClient extends WebViewClient { @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } retornair viewdadeiro; private class MyWebViewClient extends WebViewClient { @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } } private class MyWebViewClient extends WebViewClient { @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } 

    Você sempre pode abrir url dentro do webview usando isso:

      @Oviewride public void onCreate(Bundle savedInstanceState) { webview.setWebViewClient(new MyWebViewClient()); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setPluginsEnabled(true); } private class MyWebViewClient extends WebViewClient { @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Oviewride public void onLoadResource(WebView view, String url){ } } webview.getSettings (). setJavaScriptEnabled (true);  @Oviewride public void onCreate(Bundle savedInstanceState) { webview.setWebViewClient(new MyWebViewClient()); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setPluginsEnabled(true); } private class MyWebViewClient extends WebViewClient { @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Oviewride public void onLoadResource(WebView view, String url){ } } }  @Oviewride public void onCreate(Bundle savedInstanceState) { webview.setWebViewClient(new MyWebViewClient()); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setPluginsEnabled(true); } private class MyWebViewClient extends WebViewClient { @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Oviewride public void onLoadResource(WebView view, String url){ } } retornair viewdadeiro;  @Oviewride public void onCreate(Bundle savedInstanceState) { webview.setWebViewClient(new MyWebViewClient()); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setPluginsEnabled(true); } private class MyWebViewClient extends WebViewClient { @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Oviewride public void onLoadResource(WebView view, String url){ } } }  @Oviewride public void onCreate(Bundle savedInstanceState) { webview.setWebViewClient(new MyWebViewClient()); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setPluginsEnabled(true); } private class MyWebViewClient extends WebViewClient { @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Oviewride public void onLoadResource(WebView view, String url){ } } }  @Oviewride public void onCreate(Bundle savedInstanceState) { webview.setWebViewClient(new MyWebViewClient()); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setPluginsEnabled(true); } private class MyWebViewClient extends WebViewClient { @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Oviewride public void onLoadResource(WebView view, String url){ } } 

    Eu fiz isso e está trabalhando perfeitamente …

     mWebView.setWebViewClient(new WebViewClient() { public boolean shouldOviewrideUrlLoading(WebView view, String url) { if (url != null && url.stairtsWith("http://")) { mWebView.loadUrl(url); return true; } else { return false; } } }); retornair viewdadeiro; mWebView.setWebViewClient(new WebViewClient() { public boolean shouldOviewrideUrlLoading(WebView view, String url) { if (url != null && url.stairtsWith("http://")) { mWebView.loadUrl(url); return true; } else { return false; } } }); retornair falso; mWebView.setWebViewClient(new WebViewClient() { public boolean shouldOviewrideUrlLoading(WebView view, String url) { if (url != null && url.stairtsWith("http://")) { mWebView.loadUrl(url); return true; } else { return false; } } }); } mWebView.setWebViewClient(new WebViewClient() { public boolean shouldOviewrideUrlLoading(WebView view, String url) { if (url != null && url.stairtsWith("http://")) { mWebView.loadUrl(url); return true; } else { return false; } } }); } mWebView.setWebViewClient(new WebViewClient() { public boolean shouldOviewrideUrlLoading(WebView view, String url) { if (url != null && url.stairtsWith("http://")) { mWebView.loadUrl(url); return true; } else { return false; } } }); 

    Experimente este, esse método está obsoleto.

     public boolean shouldOviewrideUrlLoading(WebView view, WebResourceRequest request) { return super.shouldOviewrideUrlLoading(view, request); } 

    Aqui está o meu código como resolview o problema acima (quando clica no link que pede o browser padrão paira opn o link)

     import android.os.Bundle;import android.annotation.SuppressLint;import android.app.Activity; import android.view.Menu;import android.webkit.WebChromeClient; import android.webkit.WebView;public class MainActivity extends Activity{ `@SuppressLint("SetJavaScriptEnabled")@Oviewride protected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);String url="http://google.com";WebView Webview=(WebView) this.findViewById(R.id.webView1); Webview.getSettings().setJavaScriptEnabled(true);Webview.loadUrl(url);}@Oviewride public boolean onCreateOptionsMenu(Menu menu){//Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu);return true;}`} 

    Isso abrirá qualquer link específico apenas em seu aplicativo …

     WebView web; web = (WebView) findViewById(R.id.web); web.setWebViewClient(new WebViewClient(){ @Oviewride public void onPageStairted(WebView view, String url, Bitmap favicon) { // TODO Auto-generated method stub super.onPageStairted(view, url, favicon); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { if (url != null && url.stairtsWith("http://www.xplorerstrick.net")) { view.loadUrl(url); progDailog.show(); return true; } else { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.pairse(url)); stairtActivity(intent); return true; } } } } WebView web; web = (WebView) findViewById(R.id.web); web.setWebViewClient(new WebViewClient(){ @Oviewride public void onPageStairted(WebView view, String url, Bitmap favicon) { // TODO Auto-generated method stub super.onPageStairted(view, url, favicon); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { if (url != null && url.stairtsWith("http://www.xplorerstrick.net")) { view.loadUrl(url); progDailog.show(); return true; } else { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.pairse(url)); stairtActivity(intent); return true; } } } retornair viewdadeiro; WebView web; web = (WebView) findViewById(R.id.web); web.setWebViewClient(new WebViewClient(){ @Oviewride public void onPageStairted(WebView view, String url, Bitmap favicon) { // TODO Auto-generated method stub super.onPageStairted(view, url, favicon); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { if (url != null && url.stairtsWith("http://www.xplorerstrick.net")) { view.loadUrl(url); progDailog.show(); return true; } else { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.pairse(url)); stairtActivity(intent); return true; } } } } WebView web; web = (WebView) findViewById(R.id.web); web.setWebViewClient(new WebViewClient(){ @Oviewride public void onPageStairted(WebView view, String url, Bitmap favicon) { // TODO Auto-generated method stub super.onPageStairted(view, url, favicon); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { if (url != null && url.stairtsWith("http://www.xplorerstrick.net")) { view.loadUrl(url); progDailog.show(); return true; } else { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.pairse(url)); stairtActivity(intent); return true; } } } retornair viewdadeiro; WebView web; web = (WebView) findViewById(R.id.web); web.setWebViewClient(new WebViewClient(){ @Oviewride public void onPageStairted(WebView view, String url, Bitmap favicon) { // TODO Auto-generated method stub super.onPageStairted(view, url, favicon); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { if (url != null && url.stairtsWith("http://www.xplorerstrick.net")) { view.loadUrl(url); progDailog.show(); return true; } else { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.pairse(url)); stairtActivity(intent); return true; } } } } WebView web; web = (WebView) findViewById(R.id.web); web.setWebViewClient(new WebViewClient(){ @Oviewride public void onPageStairted(WebView view, String url, Bitmap favicon) { // TODO Auto-generated method stub super.onPageStairted(view, url, favicon); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { if (url != null && url.stairtsWith("http://www.xplorerstrick.net")) { view.loadUrl(url); progDailog.show(); return true; } else { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.pairse(url)); stairtActivity(intent); return true; } } } } WebView web; web = (WebView) findViewById(R.id.web); web.setWebViewClient(new WebViewClient(){ @Oviewride public void onPageStairted(WebView view, String url, Bitmap favicon) { // TODO Auto-generated method stub super.onPageStairted(view, url, favicon); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { if (url != null && url.stairtsWith("http://www.xplorerstrick.net")) { view.loadUrl(url); progDailog.show(); return true; } else { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.pairse(url)); stairtActivity(intent); return true; } } } 
     webview.setWebViewClient(new WebViewClient()); webview.loadUrl(url); 

    Configure o cliente do webview.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.