Nnn
- 1. package com.example.restauration7;
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
JSONParser jsonParser = new JSONParser();
private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";
public static String KEY_121="";
int success;
EditText user;
EditText passwrd;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy threadPolicy=
new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(threadPolicy);
final Button loginButton = (Button) findViewById(R.id.button1);
user = (EditText) findViewById(R.id.editText1);
passwrd=(EditText) findViewById(R.id.editText2);
String username = user.getText().toString();
KEY_121 = "http://192.168.137.64:99/Restauration/login2.php";
String password= passwrd.getText().toString();
loginButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// getServerData(usernme.getText().toString());
try{
ArrayList<NameValuePair> nameValuePairs = new
ArrayList<NameValuePair>();
nameValuePairs.add(new
BasicNameValuePair("username",user.getText().toString()));
nameValuePairs.add(new
BasicNameValuePair("password",passwrd.getText().toString()));
Log.d("request!", "starting");
JSONObject json = jsonParser.makeHttpRequest(
- 2. KEY_121, "GET",nameValuePairs);
// check your log for json response
Log.d("Login attempt", json.toString());
// json success tag
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
Log.d("Login Successful!", json.toString());
//Options.PHONE=username;
Intent ii = new
Intent(MainActivity.this,Menu.class);//here Otions.class is the activity where
we will move once login is authenticated.
finish();
startActivity(ii);
// return json.getString(TAG_MESSAGE);
}else{
//Log.d("Login Failure!", json.toString());
Log.d("Login Failure!",
json.getString(TAG_MESSAGE));
//return json.getString(TAG_MESSAGE);
}
} catch(Exception e){
e.printStackTrace();
}
}
});
//
// private String getServerData(String username) {
//
// try{
// ArrayList<NameValuePair> nameValuePairs = new
ArrayList<NameValuePair>();
// nameValuePairs.add(new
BasicNameValuePair("usernme",username));
//// nameValuePairs.add(new
BasicNameValuePair("passwrd",password));
//
// Log.d("request!", "starting");
//
// JSONObject json = jsonParser.makeHttpRequest(
// KEY_121, "GET");
//
// // check your log for json response
// Log.d("Login attempt", json.toString());
//
// // json success tag
// success = json.getInt(TAG_SUCCESS);
// if (success == 1) {
// Log.d("Login Successful!", json.toString());
// //Options.PHONE=username;
// Intent ii = new Intent(MainActivity.this,Menu.class);//here
Otions.class is the activity where we will move once login is authenticated.
// finish();
// startActivity(ii);
// return json.getString(TAG_MESSAGE);
// }else{
- 3. // //Log.d("Login Failure!", json.toString());
// Log.d("Login Failure!", json.getString(TAG_MESSAGE));
// return json.getString(TAG_MESSAGE);
//
//
// }
// } catch(Exception e){
// e.printStackTrace();
// }
// return null;
// }
}
}