Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class myWebClient extends WebViewClient
- {
- public void onReceivedHttpAuthRequest (WebView view, final HttpAuthHandler handler, String host, String realm)
- {
- Toast.makeText(getApplicationContext(), "AUTH REQUESTED", Toast.LENGTH_SHORT).show();
- super.onReceivedHttpAuthRequest(view, handler, host, realm);
- if(!mWebViewDatabase.hasHttpAuthUsernamePassword())
- {
- // Authentication dialog prompt
- AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this);
- builder.setTitle("Sign In");
- LinearLayout layout = new LinearLayout(MyActivity.this);
- layout.setOrientation(LinearLayout.VERTICAL);
- //dialog.setView(layout);
- // Set up the input
- final EditText userName = new EditText(getApplicationContext());
- // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
- userName.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL);
- userName.setHint("user name");
- userName.requestFocus();
- layout.addView(userName);
- //builder.setView(userName);
- final EditText password = new EditText(getApplicationContext());
- // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
- password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
- password.setHint("password");
- password.requestFocus();
- layout.addView(password);
- builder.setView(layout);
- // Set up the buttons
- builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- mUserName = userName.getText().toString();
- mPassword = password.getText().toString();
- handler.proceed(mUserName, mPassword);
- Log.d("Authentication", mUserName +"-->"+ mPassword);
- }
- });
- builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.cancel();
- }
- });
- builder.show();
- // end of Alert dialog prompt
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement