2012-08-27 49 views
0

我有正常工作與Android操作系統的先前版本中的WebView,但加載用於Ice Cream Sandwich的設備的問題。我正在嘗試加載的頁面需要BASIC AUTH,並且爲了非安全目的傳遞查詢字符串參數。的Android ICS WebViewClient onReceivedHttpAuthRequest不再返回用戶名和密碼

的問題是與WebViewClient.onReceivedHttpAuthRequest方法:

String[] up = view.getHttpAuthUsernamePassword(host, realm); 

它返回一個空數組,而不是用戶的ID和密碼。任何人都知道爲什麼在Android ICS中這種行爲有所不同我得到了其他版本的操作系統的用戶名和密碼。

全碼:

public class DestinationWebViewScreen extends Activity{ 

    WebView mWebView; 

    @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 

      setContentView(R.layout.destination_webview); 

      mWebView = (WebView) findViewById(R.id.social_destination_webview); 
      mWebView.getSettings().setJavaScriptEnabled(true); 
      mWebView.getSettings().setLoadsImagesAutomatically(true); 
      mWebView.clearCache(true); 
      mWebView.clearFormData(); 
      mWebView.clearHistory(); 
      mWebView.getSettings().setBuiltInZoomControls(true); 

      mWebView.setHttpAuthUsernamePassword("HOST_OF_WEBAPP","Spring Security Application", "USERID", "PASSWORD"); 

      mWebView.setWebViewClient(new WebViewClient() { 
       @Override 
       public void onReceivedHttpAuthRequest (WebView view, 
         HttpAuthHandler handler, String host,String realm){ 

        String[] up = view.getHttpAuthUsernamePassword(host, realm); 
        if(up != null && up.length == 2) { 
         handler.proceed(up[0], up[1]); 
        } 
       } 


       @Override 
       public void onPageStarted(WebView view, String url, Bitmap favicon) { 
        super.onPageStarted(view, url, favicon); 

        if(progressDialog != null){ 
         progressDialog.dismiss(); 
        } 

        showProgressbar(); 
       } 


       @Override 
       public void onPageFinished(WebView view, String url) {    
        super.onPageFinished(view, url); 

        dismissProgressDialog(); 
       } 

       @Override 
       public void onReceivedError(WebView view, int errorCode, 
         String description, String failingUrl) {     
        super.onReceivedError(view, errorCode, description, failingUrl); 

        dismissProgressDialog(); 


       } 



      }); 

    mWebView.loadUrl("https://webapphost/webapp?customerId=0-222293"); 

    IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);   
      registerReceiver(networkStateReceiver, filter); 
    } 

    public void showProgressbar() { 
     progressDialog = new CustomProgressDialog(SocialDestinationWebViewScreen.this); 
     progressDialog.getWindow().setBackgroundDrawable(getResources().getDrawable(android.R.color.transparent)); 
     progressDialog.setMessage(SocialDestinationWebViewScreen.this.getResources().getString(R.string.loading)); 
     progressDialog.show(); 
    } 


    void dismissProgressDialog(){ 

     if(progressDialog != null){ 
      progressDialog.dismiss(); 
     } 

     progressDialog = null; 
    } 

} 

回答

3

你檢查你#onReceivedHttpAuthRequest得到什麼呢?

我只是固定的,你說的話。看起來ICS不僅返回主機,而且還返回端口,如:HOST_OF_WEBAPP:80。

因此,如果在#onReceivedHttpAuthRequest中收到「HOST_OF_WEBAPP:80」,則不會檢索存儲爲「HOST_OF_WEBAPP」的內容。

試試看!

相關問題