Saturday, May 7, 2011

Authentication for Connection,WebView,VideoView

Authentication for Connections in android can be set very easily by just a pice of code:

  
DefaultHttpClient httpClient = new DefaultHttpClient();         
  
httpClient.getCredentialsProvider().setCredentials(
     new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
     new UsernamePasswordCredentials("username", "password"));

//if you dont know which host and port you are going to connect use
// AuthScope.ANY_HOST ,AuthScope.ANY_PORT or else respective values



Authentication for WebView in android can be set using following snippet:
Register a new webclient for webview and override onReceivedHttpAuthRequest method,Set handler parameter the required authentication .

//_webView is object for WebView class
_webView.setWebViewClient(new WebViewClient(){

   @Override
   public void onReceivedHttpAuthRequest(WebView view,
     HttpAuthHandler handler, String host, String realm) {
     handler.proceed("username","password");

   }
  });



Authentication for VideoView:

I didnt get any method for authentication of VideoView but a possible solution might be :

you should provide auth parameters (username/password) inside the URL. Usually this will be accepted (but not necessatilly, you should test):

http://username:password@www.yourhostname.com/whatever



Any suggestions on videoview Auth are welcomed.

No comments:

Post a Comment