Java 当用户想要在Android应用程序中购买图书时,对其进行身份验证
我用eclipse用android做了一个书店。我有一个主页,如果用户点击登录图标,进入登录,输入用户名和密码,然后按登录按钮, 如果用户找到,则显示“用户找到”,如果用户未找到,则显示警告消息“未找到”Java 当用户想要在Android应用程序中购买图书时,对其进行身份验证,java,android,http,Java,Android,Http,我用eclipse用android做了一个书店。我有一个主页,如果用户点击登录图标,进入登录,输入用户名和密码,然后按登录按钮, 如果用户找到,则显示“用户找到”,如果用户未找到,则显示警告消息“未找到” 我希望用户登录并看到消息“user found” 当用户想买书的时候可以买 而当不登录时就不能买书了 这意味着转到用户页面时(用户页面用于购买图书) 当用户登录时,此页面显示 当用户未登录此页面时,转到登录活动 , 我用国旗,但我不知道怎么用?如果flag=0,则用户不登录,如果flag=1,
我希望用户登录并看到消息“user found” 当用户想买书的时候可以买 而当不登录时就不能买书了 这意味着转到用户页面时(用户页面用于购买图书) 当用户登录时,此页面显示 当用户未登录此页面时,转到登录活动 , 我用国旗,但我不知道怎么用?如果flag=0,则用户不登录,如果flag=1,则用户登录。但如何将其传输到用户页面 你能帮我吗? 有没有这样的网站 loginactivity.java
public class LoginActivity extends Myactionbar {
EditText userNmae,pass;
HttpPost httppost;
StringBuffer buffer;
HttpResponse response;
HttpClient httpclient;
List<NameValuePair> nameValuePairs;
ProgressDialog dialog = null;
Button btnLinkToRegister;
Button btnLogin;
int flag=0;
public void gotosearch() {
Intent intent = new Intent(this, Search.class);
startActivity(intent);}
public void gotologin() {
Intent m = new Intent(this, LoginActivity.class);
startActivity(m);}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
userNmae=(EditText)findViewById(R.id.usernameedittext);
pass=(EditText)findViewById(R.id.passwordedittext);
Typeface font1 = Typeface.createFromAsset(getAssets(),
"font/bnazanin.TTF");
//emailtext
TextView userName = (TextView) findViewById(R.id.usernametv);
///tv.setText(booksote.utils.DariGlyphUtils.reshapeText("email"));
userName.setTypeface(font1);
userName.setTextSize(26);
//passwordtext
TextView password1 = (TextView) findViewById(R.id.passwordtv);
//tv.setText(booksote.utils.DariGlyphUtils.reshapeText("password"));
password1.setTypeface(font1);
password1.setTextSize(26);
//login
btnLogin= (Button) findViewById(R.id.btnLogin);
btnLogin.setTypeface(font1);
btnLogin.setTextSize(26);
**btnLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog = ProgressDialog.show(LoginActivity.this, "",
"Validating user...", true);
new Thread(new Runnable() {
public void run() {
login();
}
}).start();
}
});
}
void login(){
try{
httpclient=new DefaultHttpClient();
httppost= new HttpPost("http://10.0.2.2/project/login1.php");
//add your data
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("user_name",userNmae.getText().toString().trim())); // $Edittext_value = $_POST['Edittext_value'];
nameValuePairs.add(new BasicNameValuePair("password",pass.getText().toString().trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//Execute HTTP Post Request
response=httpclient.execute(httppost);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response = httpclient.execute(httppost, responseHandler);
System.out.println("Response :" + response);
runOnUiThread(new Runnable() {
public void run() {
dialog.dismiss();
}
});
if(response.equalsIgnoreCase("User Found")){
runOnUiThread(new Runnable() {
public void run() {
//Toast.makeText(LoginActivity.this,"Login Success", Toast.LENGTH_SHORT).show();
//this I use flag but I dontknow how to use ?
flag=1;
**Intent intent = new Intent(getApplicationContext(),UserPage.class);
intent.putExtra("flag", flag);**
startActivity(intent);**
}
});
}else{
flag=0;
showAlert();
}
}catch(Exception e){
dialog.dismiss();
System.out.println("Exception : " + e.getMessage());
}
}
public void showAlert(){
LoginActivity.this.runOnUiThread(new Runnable() {
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
builder.setTitle("Login Error.");
builder.setMessage("not found")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
}
如果用户只有在成功登录后才能访问UserPage,并且UserPage是您唯一可以购买书籍的地方,为什么您首先需要此标志?@Takendarkk i want flag表示用户登录的所有活动。如果flag=0 user dos'nt login,如果flag=1 user login,则用户即使不登录也可以使用应用程序中的所有活动?@Takendarkk是,但在一个活动(userpage)中必须登录,用户页面用于购买图书,因此用户应该登录购买图书。@Takendark请帮助我。。。
public class UserPage extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_page);
Intent intent = getIntent();
int myflag = intent.getIntExtra("flag");
}