Login screen on Android

Asked

Viewed 1,720 times

2

I emulated a local server by XAMPP and started trying to develop a login screen for an Android application.

It is working perfectly, but only when I log in through localhost(using my local IP address instead of the localhost, because AVD does the access as if the server were online) and entering the password and login already pre-defined. I want to make the login validated when accessing the following page: http://siga.ufvjm.edu.br/.

I can make it work by modifying only part of the code below? The fact that the system is done using the MIOLO Framework affects something?

btAcessar.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Log.i("Logar", "Entrou no evento");
        String urlPost="http://localhost/android/logar.php";
        String urlGet="http://localhost/android/logar.php?usuario="+etUsuario.getText().toString()+"&senha="+etSenha.getText().toString();
        ArrayList<NameValuePair> parametrosPost = new ArrayList<NameValuePair>();
        parametrosPost.add(new BasicNameValuePair("usuario", etUsuario.getText().toString()));
        parametrosPost.add(new BasicNameValuePair("senha", etSenha.getText().toString()));
        String respostaRetornada = null;
        Log.i("Logar", "Vai entrar no try");

        try{
            respostaRetornada = ConexaoHttpClient.executaHttpPost(urlPost, parametrosPost);
            //respostaRetornada = ConexaoHttpClient.executaHttpGet(urlGet);
            String resposta = respostaRetornada.toString();
            Log.i("Logar", "resposta = "+resposta);
            resposta = resposta.replaceAll("\\s+", "");
            if(resposta.equals("1"))
                startActivity(new Intent(Logar.this, MenuPrincipal.class));
                //mensagemExibir("Login", "Usuário Válido.");
            else
                mensagemExibir("Login", "Usuário Iválido.");
        }
        catch(Exception erro){
            Log.i("Erro", "erro = "+erro);
            Toast.makeText(Logar.this, "Erro.: "+erro, Toast.LENGTH_LONG);
        }
    }
});

What changes will be necessary for me to go ahead?

Logcat report when I replace localhost with address http://siga.ufvjm.edu.br/index.php?module=common&action=main:

10-09 12:54:09.709: I/Logar(930): Entrou no evento
10-09 12:54:09.709: I/Logar(930): Vai entrar no try
10-09 12:54:09.969: I/logar(930): resposta = <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
10-09 12:54:09.969: I/logar(930): <html>
10-09 12:54:09.969: I/logar(930): <head>
10-09 12:54:09.969: I/logar(930): <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
10-09 12:54:09.969: I/logar(930): <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1" />
10-09 12:54:09.969: I/logar(930): <title>SIGA :: UFVJM</title>
10-09 12:54:09.969: I/logar(930): <link rel="shortcut icon" href="http://siga.ufvjm.edu.br/images/icon_siga.gif" />
10-09 12:54:09.969: I/logar(930): <link rel="stylesheet" type="text/css" href="http://siga.ufvjm.edu.br/index.php?module=miolo&amp;action=themes:system:m_themeelement.css">
10-09 12:54:09.969: I/logar(930): <link rel="stylesheet" type="text/css" href="http://siga.ufvjm.edu.br/index.php?module=miolo&amp;action=themes:system:m_controls.css">
10-09 12:54:09.969: I/logar(930): <link rel="stylesheet" type="text/css" href="http://siga.ufvjm.edu.br/index.php?module=miolo&amp;action=themes:system:m_forms.css">
10-09 12:54:09.969: I/logar(930): <link rel="stylesheet" type="text/css" href="http://siga.ufvjm.edu.br/index.php?module=miolo&amp;action=themes:system:m_common.css">
10-09 12:54:09.969: I/logar(930): <link rel="stylesheet" type="text/css" href="http://siga.ufvjm.edu.br/index.php?module=miolo&amp;action=themes:system:m_boxes.css">
10-09 12:54:09.969: I/logar(930): <link rel="stylesheet" type="text/css" href="http://siga.ufvjm.edu.br/index.php?module=miolo&amp;action=themes:system:forms.css">
10-09 12:54:09.969: I/logar(930): <link rel="stylesheet" type="text/css" href="http://siga.ufvjm.edu.br/index.php?module=miolo&amp;action=themes:system:tabelas.css">
10-09 12:54:09.969: I/logar(930): <link rel="stylesheet" type="text/css" href="http://siga.ufvjm.edu.br/index.php?module=miolo&amp;action=themes:system:siga.css">
10-09 12:54:09.969: I/logar(930): <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
10-09 12:54:09.969: I/logar(930): <meta name="Generator" content="MIOLO Version Miolo 2.0 beta1; http://www.miolo.org.br">
10-09 12:54:09.969: I/logar(930): <script type="text/javascript" src="http://siga.ufvjm.edu.br/scripts/prototype/prototype.js"></script>
10-09 12:54:09.969: I/logar(930): <script type="text/javascript" src="http://siga.ufvjm.edu.br/scripts/m_miolo.js"></script>
10-09 12:54:09.969: I/logar(930): <script type="text/javascript" src="http://siga.ufvjm.edu.br/scripts/m_compatibility.js"></script>
10-09 12:54:09.969: I/logar(930): <script type="text/javascript" src="http://siga.ufvjm.edu.br/scripts/m_form.js"></script>
10-09 12:54:09.969: I/logar(930): <script type="text/javascript">
10-09 12:54:09.969: I/logar(930): miolo.onSubmit = function ()
10-09 12:54:09.969: I/logar(930): {
10-09 12:54:09.969: I/logar(930):     this.submit();
10-09 12:54:09.969: I/logar(930):     return true;
10-09 12:54:09.969: I/logar(930): }
10-09 12:54:09.969: I/logar(930): window.onload = function () {
10-09 12:54:09.969: I/logar(930): MIOLO_GetElementById('uid').focus();
10-09 12:54:09.969: I/logar(930):    miolo.setTitle('SIGA :: UFVJM');
10-09 12:54:09.969: I/logar(930): miolo.setForm('frm543685723f9db');
10-09 12:54:09.969: I/logar(930): form_frm5436857246321 = new Miolo.form('frm5436857246321');
10-09 12:54:09.969: I/logar(930): }
10-09 12:54:09.969: I/logar(930): //-->
10-09 12:54:09.969: I/logar(930): </script>
10-09 12:54:09.969: I/logar(930): </head>
10-09 12:54:09.969: I/logar(930): <body class="m-theme-body">
10-09 12:54:09.969: I/logar(930): <form id="frm543685723f9db" name="frm543685723f9db" method="post" action="http://siga.ufvjm.edu.br/index.php?module=common&amp;action=main"  onSubmit="return miolo.onSubmit();" > 
10-09 12:54:09.969: I/logar(930): <div id="m-container">
10-09 12:54:09.969: I/logar(930): <div id="m-container-top">
10-09 12:54:09.969: I/logar(930): <div class="m-box-title"><span class="icon">
10-09 12:54:09.969: I/logar(930): <img src="http://siga.ufvjm.edu.br/index.php?module=miolo&amp;action=themes:system:images:icon_siga.gif" alt="" border="0"></span><span class="caption">&nbsp;SIGA&nbsp;-&nbsp;Sistema&nbsp;Integrado&nbsp;de&nbsp;Gest?o&nbsp;Acad?mica&nbsp;&nbsp;</span></div></div>
10-09 12:54:09.969: I/logar(930): <div id="m-container-module">
10-09 12:54:09.969: I/logar(930): <div id="m_m4" class="m-module-header"></div></div>
10-09 12:54:09.969: I/logar(930): <div id="m-container-content-full">
10-09 12:54:09.969: I/logar(930): <div style="float:left;margin-right:5px">
10-09 12:54:09.969: I/logar(930): <img src="http://siga.ufvjm.edu.br/index.php?module=miolo&amp;action=themes:system:images:logo_siga.jpg" alt="Home" border="0"></div>
10-09 12:54:09.969: I/logar(930): <div style="width:650px;float:left;margin-right:5px">
10-09 12:54:09.969: I/logar(930): <div id="frm5436857246321" class="m-form-box">
10-09 12:54:09.969: I/logar(930): <div id="m10" class="m-box-outer m-form-outer">
10-09 12:54:09.969: I/logar(930): <div class="m-box-box">
10-09 12:54:09.969: I/logar(930): <div class="m-box-title"><span class="icon">
10-09 12:54:09.969: I/logar(930): <img src="http://siga.ufvjm.edu.br/index.php?module=common&amp;action=html:images:lock.png" alt="" border="0"></span><span class="caption">Acesso&nbsp;ao&nbsp;Sistema&nbsp;&nbsp;</span></div>
10-09 12:54:09.969: I/logar(930): <div class="m-form-body">
10-09 12:54:09.969: I/logar(930): <div>
10-09 12:54:09.969: I/logar(930): <div class="m-form-row"><span class="label" style="width:25%">
10-09 12:54:09.969: I/logar(930): <label  class="m-caption" for="uid">Usu&aacute;rio:</label></span><span class="field" style="width:70%">
10-09 12:54:09.969: I/logar(930): <input  type="text" id="uid" class="m-text-field" name="uid" value="" size="20"></span></div>
10-09 12:54:09.969: I/logar(930): <div class="m-form-row"><span class="label" style="width:25%">
10-09 12:54:09.969: I/logar(930): <label  class="m-caption" for="pwd">Senha:</label></span><span class="field" style="width:70%">
10-09 12:54:09.969: I/logar(930): <input  typ
10-09 12:54:10.099: D/dalvikvm(930): GC_FOR_ALLOC freed 236K, 13% free 2723K/3104K, paused 25ms, total 28ms
10-09 12:54:10.319: I/Choreographer(930): Skipped 54 frames!  The application may be doing too much work on its main thread.
  • You need to explain better what you need, but from what I understand, you want to log on to a website, right ? If yes, to begin with, the url you should try to make a post is http://siga.ufvjm.edu.br/index.php?module=common&action=main and the parameters are uid (login) and pwd (password).

  • That’s exactly what I intend to do. I have tried to add this information in the code, both the link and the parameters, but not yet succeeded with only this data.

  • 1

    It is interesting that you add the server answer to the question.

  • @Marpd144, is managing the Cookies? In general the system must keep a user session with Cookies.

  • @Luídne, I’ll do it. Thank you. I may be messing around asking this, but the fact that the university system is made using the MIOLO Framework affects something?

  • @Wakim, I’m not, I haven’t studied that part yet. Would it be essential for functioning? Thank you

  • @Marpd114, yes it is paramount to manage the sending and receiving of cookies. Otherwise you may always receive an expired session message or without permission.

  • @Wakim, I will give a study on that part tbm. Thank you

  • First detail IMPORTATE! , 10-09 12:54:10.319: I/Choreographer(930): Skipped 54 frames! The application may be doing too much work on its main thread. Use treads to do work in the application. one-night stand here.

Show 4 more comments

1 answer

2

Use Threads to do heavy work in your application, such as disk access, downloads, image processing, etc... read more. If you lock the main thread of the process, the application will receive a ANR. ie you can’t lock the main thread for more than 5 seconds and in case of Broadscast, no more than 10 seconds.

10-09 12:54:09.969: I/logar(930): <label  class="m-caption" for="pwd">Senha:</label></span><span class="field" style="width:70%">
10-09 12:54:09.969: I/logar(930): <input  typ
10-09 12:54:10.099: D/dalvikvm(930): GC_FOR_ALLOC freed 236K, 13% free 2723K/3104K, paused 25ms, total 28ms
10-09 12:54:10.319: I/Choreographer(930): Skipped 54 frames!  The application may be doing too much work on its main thread.

The server’s response is incomplete, probably because the process was interrupted by long crashing the main thread, as you said, using local server works perfectly because using local network ( your machine ) response time is fast enough not to hang the main thread for too long.

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
         protected Long doInBackground(URL... urls) {
             int count = urls.length;
             long totalSize = 0;
             for (int i = 0; i < count; i++) {
                 totalSize += Downloader.downloadFile(urls[i]);
                 publishProgress((int) ((i / (float) count) * 100));
                 // Escape early if cancel() is called
                 if (isCancelled()) break;
             }
             return totalSize;
         }

         protected void onProgressUpdate(Integer... progress) {
             setProgressPercent(progress[0]);
         }

         protected void onPostExecute(Long result) {
             showDialog("Downloaded " + result + " bytes");
         }
     }

To run the thread.

new DownloadFilesTask().execute(url1, url2, url3);
  • It is certainly a good practice to use Asynctask, but according to the question, the problem is not ANR.

  • 1

    It is not ANR if the answer is fast enough, now it puts access to an unstable network, it is without a doubt that will give an ANR. ANR will become the main problem, in addition to using threads for data access by networks is not only a good practice , but rather fundamental to the operation of the application, In short using Thread in this problem is the first solution that should be done.

  • Good explanation, @Duannistoncardosocabral. I’ll follow your reasoning and see where it goes. Soon post a feedback. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.