用户身份验证,登录页面进入webview

时间:2014-03-06 05:16:38

标签: android authentication webview

我正在将一个带有登录页面的网站加载到我的WebView中。我希望用户登录该网站,然后当用户通过身份验证时,我想加载另一个活动..

我是网络身份验证的新手,不知道如何继续这项工作。 请通过任何合适的示例或教程指导我如何实现这一目标。

这就是我的尝试: -

myWebView.setWebViewClient(new WebViewClient()
    {

        @Override
        public void onPageFinished(WebView view, String url) 
        {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);
            if(progressBar.isShowing())
            {
                progressBar.dismiss();
            }
            String redirected = view.getUrl();
            //redirected = Uri.decode(redirected);

        }

        /*@Override
        public void onReceivedLoginRequest(WebView view, String realm,
                String account, String args)
        {
            // TODO Auto-generated method stub

            super.onReceivedLoginRequest(view, realm, account, args);
            if(!DeviceInformation.IsDeviceRegistered) 
            {
                return;
            }
            UserInformation userInfo = DeviceManagement.AuthenticateDevice(encodedAccountName, deviceId, hostUrl);

            AuthenticationInformation.SetUserInformation(userInfo);

            String en = userInfo.toString();

             // just for refernece..Change later
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Details.this);
            alertDialogBuilder.setNegativeButton("Ok", new DialogInterface.OnClickListener() 
            {
                public void onClick(DialogInterface dialog,int id) 
                {
                    // if this button is clicked, just close
                    // the dialog box and do nothing
                    dialog.cancel();
                }
            });
            AlertDialog alert = alertDialogBuilder.create();
            alert.setMessage(en);
            alert.show();
        }*/


        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            // TODO Auto-generated method stub
            view.loadUrl(url);

            HttpClient httpClient = new DefaultHttpClient();
            URL myUrl;
            URLConnection connection;
            try
            {
                myUrl = new URL(url);
                connection = myUrl.openConnection();
                connection.setConnectTimeout(3000);
                connection.connect();

                int size = connection.getContentLength();

            }
            catch (Exception e) {}

            String htmlContent = "";
            HttpPost httpGet = new HttpPost(url);
            HttpResponse response;

            try
            {
                response = httpClient.execute(httpGet);
                if(response.getStatusLine().getStatusCode() == 200)
                {
                    HttpEntity entity = response.getEntity();
                    if (entity != null)
                    {
                        InputStream inputStream = entity.getContent();
                        htmlContent = convertToString(inputStream);

                    }
                }
            }
            catch (Exception e) {}




            return true;

        }

0 个答案:

没有答案