I have created a project for A User with Login Page. I need to Login into the Application using jSON with PHP.
public class login extends Activity {
EditText e1, e2;
Button bt1, bt2;
String s1, s2, Authendication;
String S1,S2,u1[],p1[];
String Uname;
int i=0,j=0;
Resources res;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
e1 = (EditText) findViewById(R.id.userName);
e2 = (EditText) findViewById(R.id.pwd);
bt1 = (Button) findViewById(R.id.btLogin);
bt2 = (Button) findViewById(R.id.btExit);
res = getResources();
DBConnect dc=new DBConnect(this);
try {
SQLiteDatabase sqdb = db.getReadableDatabase();
Cursor c = sqdb.rawQuery("select UserID,password from User", null);
if (c != null) {
if (c.moveToFirst()) {
do {
S1=S1+","+c.getString(c.getColumnIndex("UserID"));
S2=S2+","+c.getString(c.getColumnIndex("password"));
i++;
} while (c.moveToNext());
}
}
} catch (Exception e) {
Toast.makeText(login.this, e.toString(), Toast.LENGTH_LONG).show();
}
bt1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
int s = 0;
String regex = "(,)";
u1 = S1.split(regex);
p1 = S2.split(regex);
s1 = e1.getText().toString();
s2 = e2.getText().toString();
for (j = 0; j <= i; j++)
{
if((s1.equals(u1[j])) && (s2.equals(p1[j])))
{
s=1;
Toast.makeText(login.this, "Login Successfully",
Toast.LENGTH_LONG).show();
Intent i1 = new Intent("My Next Screen");
startActivity(i1);
}
}
if(s == 0){
Toast.makeText(login.this, "Login fail",
Toast.LENGTH_LONG).show();
}
}
});
bt2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
e2.setText("");
finish();
}
});
}
}
And My Xml File have 2 Edit Box and 2 Buttons. Can i perform these option with the PHP for Server Database with JSON..
Help me achieve this.
Use the Following Methods for your’s coding..
And use the following Link also..
Android PHP connection through Java