2013-02-20 5 views
1

webview에서 URL을 열려고하는데 외부 브라우저에서 URL을 열고 있습니다. www.google.com 다음 URL은 웹보기에서 여는 : URL이 HTTPS 인 경우webview loadUrl은 브라우저에서 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(); 
     } 
    } 

} 

입니다. 나는 해결책을 찾기 위해 열심히 봤지만 그것을 찾을 수 없습니다. 문제를 해결하는 방법?

답변

2

문제는에 당신의

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)

확인을 위해 로그를 입력하면 잘못된 것을 알 수 있습니다.

+0

예. 내 실수입니다. –

+0

thnks buddy !! 내 시간을 저장 했어. –

관련 문제