Help! Trying to get Basic Auth working with WebView. setHttpAuthUsernamePassword?

by Stoffe » Fri, 16 Oct 2009 07:39:19 GMT


Sponsored Links
 Hi Matt!

You need to do something like this:

@Override
public void onCreate(Bundle savedInstanceState) {

WebView webkit = (WebView) findViewById(R.id.web_view);




--~--~---------~--~----~------------~-------~--~----~



Help! Trying to get Basic Auth working with WebView. setHttpAuthUsernamePassword?

by Stoffe » Fri, 16 Oct 2009 07:39:20 GMT


 Hi Matt!

@Override
public void onCreate(Bundle savedInstanceState) {

    WebView webkit = (WebView) findViewById(R.id.web_view);
    webkit.setHttpAuthUsernamePassword(page.getHost(), realm,
username, password);
    webkit.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]);
            }
            else{
                Log.d("WebAuth","Could not find user/pass for domain :"+
                        host+" with realm = "+realm);
           }
        }
    });
    webkit.loadUrl(page.toString());

BR Stoffe




--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Help! Trying to get Basic Auth working with WebView. setHttpAuthUsernamePassword?

by Stoffe » Tue, 20 Oct 2009 23:15:29 GMT


 Hi!

Just one more discovery that in my opinion is probably a bug in the
framework.
When you call setHttpAuthUsernamePassword only the first call is
stored.
If you try override values for the same host and realm it will only
return the first entered user.
Even after restarts of the client.

I even had clearCache(true) and that did not help.
So if you need to update a value you must first call.

WebViewDatabase.getInstance(this).clearHttpAuthUsernamePassword();
In my example you could as well skip the entire setHttpAuth/
getHttpAuth and pass the correct value but if you split the logic then
it matters.

BR Stoffe





--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Using distance in android.graphics.Point

Hi All,

I am trying to find distance between 2 Points using
android.graphics.Point.

I am passing 2 Point parameters to the function -  public static float
distance(Point a, Point b)

Unfortunately, it gives me the following error:

ERROR/AndroidRuntime(1962): Uncaught handler: thread Main exiting due
to uncaught exception
ERROR/AndroidRuntime(1962): java.lang.UnsatisfiedLinkError: length
ERROR/AndroidRuntime(1962):     at
android.graphics.Point.length(Native Method)
ERROR/AndroidRuntime(1962):     at
android.graphics.Point.distance(Point.java:98)


Please let me know any solution if you have.

Thanks,
Kishore

--~--~---------~--~----~------------~-------~--~----~

2. Helo with onActivityResult()

I am starting a sub activity that browses for a file, then in the
onActivityResult() method I parse the file that is returned.  The trouble is
that the parsing takes a little while and I am trying to pop up a progress
dialog, but the file browser is visible until the onActivityResult() method
finishes.  Is there some way that I can force the file browser to go away
and show the calling activity so the progress dialog will show?

--~--~---------~--~----~------------~-------~--~----~

3. Open GL Tutorial problem

4. TextView Error (ERROR/TextView: Need text Layout but do not have a width)

5. AndNav - Update

6. Android Tutorial - Option and Context menu

7. Android Tutorial - XML View inflation