Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have the following code. It authenticates the user password. you should call this method inside doBackground() of AsyncTask extended Class.</p> <pre><code>public boolean authenticate(String strUsername, String strPassword) { boolean bReturn = false; InputStream pInputStream = null; ArrayList&lt;NameValuePair&gt; pNameValuePairs = new ArrayList&lt;NameValuePair&gt;(); pNameValuePairs.add(new BasicNameValuePair("userid", strUsername)); pNameValuePairs.add(new BasicNameValuePair("password", strPassword)); try { HttpClient pHttpClient = new DefaultHttpClient(); String strURL = p_strServerIP + "Login.php"; HttpPost pHttpPost = new HttpPost(strURL); pHttpPost.setEntity(new UrlEncodedFormEntity(pNameValuePairs)); HttpResponse pHttpResponse = pHttpClient.execute(pHttpPost); HttpEntity pHttpEntity = pHttpResponse.getEntity(); pInputStream = pHttpEntity.getContent(); BufferedReader pBufferedReader = new BufferedReader(new InputStreamReader(pInputStream,"iso-8859-1"),8); StringBuilder pStringBuilder = new StringBuilder(); String strLine = pBufferedReader.readLine(); pInputStream.close(); if(strLine != null) { if((strLine).equals("permit")) { bReturn = true; } } } catch (Exception e) { Log.e("log_tag", "Caught Exception @ authenticate(String strUsername, String strPassword):" + e.toString()); } return bReturn; } </code></pre> <p>The class you extend from AsyncTask should be something like</p> <pre><code>class ConnectionTask extends AsyncTask&lt;String, Void, Boolean&gt; { private SharedPreferences mSettings; private Context mContext; ConnectionTask(SharedPreferences settings, Context context) { mSettings = settings; mContext = context; } protected void onProgressUpdate(Integer... progress) { } protected void onPostExecute(Boolean result) { Toast.makeText(mContext, "Authentication over.", Toast.LENGTH_LONG).show(); } @Override protected Boolean doInBackground(String... params) { pVerifier.authenticate(params[0], params[1]); return true; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload