Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6131393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:58:09+00:00 2026-05-23T16:58:09+00:00

I would like to show a protected Blog into a webview. The blog is

  • 0

I would like to show a protected Blog into a webview.
The blog is on Google’s blogger.com

The username & password are provided by the app itself (so that the user does not have to type in anything):

I’m using the following code but it does not work, as it is asking the user to type in its username and password (at the first log only, then it is saved and it works fine)? What’s wrong ? What should I be using as ‘realm’ in :

webview.setHttpAuthUsernamePassword(URL_WebView, "", getString(R.string.username), getString(R.string.password));

The whole code so far :

public class Main extends Activity {
/** Called when the activity is first created. */

String URL_WebView = "http://myblog.blogspot.com/";

public static Context mContext;
static SharedPreferences prefs;

static int log_number;
Boolean terms_agreed;           

//GoogleAnalyticsTracker tracker;
//static String analytics_tracker = "UA-11967031-29";

WebView webview;
private static final FrameLayout.LayoutParams ZOOM_PARAMS = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);


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

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);
    this.webview = (WebView)findViewById(R.id.webkitWebView1);

    mContext = this;

    reading_the_prefs();
    log_number = log_number + 1;

    if (log_number >= 2) {
        if ((!terms_agreed)){
            TermsDialog();
        }
    }

    /*
    tracker = GoogleAnalyticsTracker.getInstance();
    tracker.start(analytics_tracker, this);
    tracker.trackPageView("/Main");
    */

    // adding the zoom controls ...
    FrameLayout mContentView = (FrameLayout) getWindow().getDecorView().findViewById(android.R.id.content);
    final View zoom = this.webview.getZoomControls();
    mContentView.addView(zoom, ZOOM_PARAMS);
    zoom.setVisibility(View.GONE);

    WebSettings settings = webview.getSettings();
    settings.setJavaScriptEnabled(true);
    webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

    webview.setWebViewClient(new MyWebViewClient ());

    //webview.savePassword(URL_WebView, getString(R.string.username), getString(R.string.password));    
    webview.setHttpAuthUsernamePassword(URL_WebView, "", getString(R.string.username), getString(R.string.password));   
    webview.loadUrl(URL_WebView);

}

//======================================================================================

private class MyWebViewClient extends WebViewClient {

    public void onReceivedHttpAuthRequest(WebView view,
            HttpAuthHandler handler, String host, String realm) {

        handler.proceed(getString(R.string.username), getString(R.string.password));        
        Log.i("Hub","Host ="+host+" with realm ="+realm);
    }

    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        Log.e("Hub", "Error: " + description);
        Toast.makeText(Main.this, "Oh no! " + description, Toast.LENGTH_LONG).show();
    }
}

//======================================================================================

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, 99, 3, "Exit").setIcon(android.R.drawable.ic_menu_delete);
    menu.add(0, 999, 2, "Terms of Service").setIcon(android.R.drawable.ic_menu_agenda);
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()){
    case 99:
        finish();
        break;
    case 999:
        //tracker.trackPageView("/TERMS_OF_SERVICE");
        TermsDialog();
        break;
    }
    return super.onOptionsItemSelected(item);
}

// =================================================================================
public void TermsDialog(){

    AlertDialog.Builder ad = new AlertDialog.Builder(this);
    ad.setIcon(R.drawable.icon);
    // custom Title - that's the way I found to center it !
    TextView title = new TextView(mContext);
    title.setText(R.string.TermsDialog_Title);
    title.setBackgroundColor(Color.BLACK);
    title.setPadding(10, 10, 10,10);
    title.setGravity(Gravity.CENTER);
    title.setTextColor(Color.WHITE);
    title.setTextSize(20);
    // to center the TITLE :
    ad.setCustomTitle(title);

    ad.setView(LayoutInflater.from(this).inflate(R.layout.terms_dialog,null));

    ad.setPositiveButton(R.string.TermsDialog_Yes, 
            new android.content.DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int arg1) {
            //OK, save accepted Terms and Service into the Prefs.
            terms_agreed = true;
            //tracker.trackPageView("/Terms_agreed");
            saving_the_prefs();
        }
    }
    );

    ad.setNegativeButton(R.string.TermsDialog_No, 
            new android.content.DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int arg1) {
            terms_agreed = false;
            //tracker.trackPageView("/Terms_NOT_agreed");
            saving_the_prefs(); 
            finish();
        }
    }
    );

    ad.setCancelable(false);

    ad.show();
}

// =================================================================================
private void reading_the_prefs() {

    prefs = getSharedPreferences("Market_Wrap", 0);
    log_number = prefs.getInt("log_number" , 0);
    terms_agreed = prefs.getBoolean("terms", false);
    Log.i("Hub", "log_number="+log_number);  
    Log.i("Hub", "terms_agreed="+terms_agreed);  

}
// =================================================================================
public void saving_the_prefs() {

    prefs = getSharedPreferences("Market_Wrap", 0);
    SharedPreferences.Editor editor = prefs.edit();

    editor.putInt("log_number", log_number);
    editor.putBoolean("terms", terms_agreed);
    editor.commit();
}
// =================================================================================

@Override
protected void onPause() {
    super.onPause();

    //tracker.dispatch();
    //tracker.stop();
    saving_the_prefs();
}
// =================================================================================

}

I have tried to follow the advice here but it looks like

public void onReceivedHttpAuthRequest(WebView view,
            HttpAuthHandler handler, String host, String realm) {

        handler.proceed(getString(R.string.username), getString(R.string.password));        
        Log.i("Hub","Host ="+host+" with realm ="+realm);
    }

never gets triggered (in MyWebViewClient) for whatever reason ?

EDIT : Maybe I need to implement a client-side OAuth on Android ?

like here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:58:10+00:00Added an answer on May 23, 2026 at 4:58 pm

    From setHttpAuthUsernamePassword, you need to pass in the host of the site: so if you are accessing (for example) http://www.google.com with username and password from your code and realm Protected, you would do

    webview.setHttpAuthUsernamePassword("www.google.com", "Protected", getString(R.string.username), getString(R.string.password));
    

    You can get the realm by looking at the published realm in your browser: for example, in Firefox if you open http://tools.dynamicdrive.com/password/example/ you will see that the following text in the caption: A username and password are being requested by http://tools.dynamicdrive.com. The site says: “Restricted Area. In this case the realm is Restricted Area.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to show the system form name into the caption of the
I would like to write an app to show a progress dialog while waiting
i would like to show my current position on an android phone using google
I would like to show the value of a variable in a TextView, like
I would like to show and hide a div during hover and hover out.
I would like to show a div based on the Onclick event of an
I would like to show divs at a specific interval (10 seconds) and show
I would like to show different tabs in the top navigation of a SharePoint
I would like to Show my Messagebox in the center of its parent form.
I would like to show a modal progress wheel overlay on my view. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.