2016-03-19 63 views
0

嗨,我所做的只使用網頁視圖來看看我的IP攝像頭的Android應用程序,但我的攝像頭詢問用戶名和密碼,每次我打開應用程序: enter image description here有沒有辦法讓android webview記住密碼?

有沒有辦法讓Android網頁視圖還記得那些密碼,所以我不必每次輸入密碼?

我正在使用Visual Studio,C#和Xamarin。

我還應該提到,我是新編程,特別是在android上,謝謝。

回答

0

WebViewClient類有一個回調方法OnReceivedHttpAuthRequest,當服務器需要用戶名和密碼時,由WebView調用。此方法的其中一個參數是接口HttpAuthHandler。您可以通過調用此處理程序上的方法來控制授權請求。

因此,解決方案是創建一個WebViewClient子類,該子類覆蓋OnReceivedHttpAuthRequest並調用HttpAuthHandler上的適當方法。然後將您的WebView設置爲具有此子類的實例。

這裏的鏈接到Xamarin文檔:OnReceivedHttpAuthRequest - Xamarin

. 
    . 
    . 
    var client = new MyWebViewClient(); 
    WebView web = FindViewById<WebView>(Resource.Id.webView1); 
    web.SetWebViewClient(client); 
    . 
    . 
    . 


class MyWebViewClient : WebViewClient { 

    public override void OnReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, string host, string realm) { 

     handler.Proceed(username, password); 
    } 
} 
相關問題