[Java for Android App Development] jaker125:
Alright so, this may get a bit confusing so feel free to ask me what the hell I'm talking about.

I am developing and app to run along side of a PHP web panel that is in development. I've been searching around for a way to hand logins on the app. The best method I could find that appears to suite our needs is to POST to HTTP. However while setting up the login file based on a tutorial I found, it doesn't seem to pull the data back properly. We are using a mysql database however we recently revamped the site and moved from mysql_query to PDO statements(not sure if that has anything to do with it).

Anyways what currently happens is you click login it checks the page and returns false all the time, unless the word "true" is echo'ed.

Here is my current code on the app side:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Login extends Activity implements OnClickListener{
Button ok,back,exit;
TextView result;

[MENTION=439709]override[/MENTION]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

ok = (Button)findViewById(R.id.button_login);
ok.setOnClickListener(this);

result = (TextView)findViewById(R.id.login_text);
}

public void postLoginData(){
new Thread(new Runnable(){
public void run(){
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new HttpPost("myurl");

try
{
EditText uname = (EditText)findViewById(R.id.usernamelogin);
String username = uname.getText().toString();

EditText pword = (EditText)findViewById(R.id.passwordlogin);
String password = pword.getText().toString();

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("submit", "login"));
nameValuePairs.add(new BasicNameValuePair("username", username));
nameValuePairs.add(new BasicNameValuePair("password", password));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

Log.w("TMCP", "Execute HTTP Post Request");
HttpResponse response = httpclient.execute(httppost);

String str = inputStreamToString(response.getEntity().getContent()).toString();
Log.w("TMCP", str);

if(str.toString().equalsIgnoreCase("true"))
{
Log.w("TMCP", "TRUE");
}
else
{
Log.w("TMCP", "FALSE");
}
} catch(ClientProtocolException e){
e.printStackTrace();
} catch(IOException e){
e.printStackTrace();
}
}
}).start();

}

private StringBuilder inputStreamToString(InputStream is) {
String line = "";
StringBuilder total = new StringBuilder();
// Wrap a BufferedReader around the InputStream
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
// Read response until the end
try {
while ((line = rd.readLine()) != null) {
total.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
// Return full string
return total;
}

[MENTION=439709]override[/MENTION]
public void onClick(View view) {
if(view == ok){
postLoginData();
}
}

}

Is there another way I should go about tackling this project? Besides logins I'm going to need the app to pull results from the database to create Lists, and Various other functions.

Thanks in advance for the help.

JakeR