Android webview加载url在浏览器中打开url

Android webview加载url在浏览器中打开url,android,https,android-webview,Android,Https,Android Webview,我试图在webview中打开url,但它正在外部浏览器中打开url 我的代码是 public class MainActivity extends Activity { private WebView webView; String URL = "https://login.salesforce.com/services/oauth2/authorize?response_type=token&display=touch&client_id=3MVG9Y6d_

我试图在webview中打开url,但它正在外部浏览器中打开url

我的代码是

public class MainActivity extends Activity
{

    private WebView webView;

    String URL = "https://login.salesforce.com/services/oauth2/authorize?response_type=token&display=touch&client_id=3MVG9Y6d_Btp4xp7w.6oGLerlRztTTUKMEL8QWHvuB5miUgdJzQ0HgnMB7dhm1mTiluRv4ud9cZYeFcAz7hXP&redirect_uri=https%3A%2F%2Flogin.salesforce.com%2Fservices%2Foauth2%2Fsuccess";
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);



        setContentView(R.layout.webview);

        webView = (WebView) findViewById(R.id.webView1);
        webView.getSettings().setJavaScriptEnabled(true);

        webView.getSettings().setDomStorageEnabled(true);
        webView.loadUrl(URL);
        //webView.loadUrl("https://www.google.co.in/");
        webView.setWebViewClient(new MyWebViewClient());
    }

    private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (Uri.parse(url).getHost().equals(url)) {
                // This is your web site, so do not override; let the WebView to load the page
                return false;
            }
            // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
            return true;
        }

        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            super.onReceivedSslError(view, handler, error);

            // this will ignore the Ssl error and will go forward to your site
            handler.proceed();
        }
    }

}
如果url为https:www.google.com,则该url仅在webview中打开。我在谷歌上搜索了很难找到解决方案,但我找不到。如何解决问题?

问题在您的解决方案中

    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (Uri.parse(url).getHost().equals(url)) {
            // This is your web site, so do not override; let the WebView to load the page
            return false;
        }
        // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(intent);
        return true;
    }
它试图以不同的目的加载URL,因此您的默认浏览器开始工作。 你到底想问什么

parse(url).getHost().equals(url)


试着把检查日志放进去,你会发现出了什么问题。

thnks buddy!!节省了我的时间