现在有一个按钮,当他点击它将进入登录页面。如果他不是注册用户,他可以注册自己并再次使用用户名和密码登录。一旦他用他的用户名和密码登录他将是允许从服务器下载n个音频文件。
所以我想要实现的是,一旦用户是注册用户并登录并退出应用程序,但如果注册用户想要下载更多文件,则不应该使用用户名和密码提示他,因为他是注册用户
如何实现这一目标?
登录注册用户的代码:
ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();
nvp.add(new BasicNameValuePair("userid", userid.getText().toString()));
nvp.add(new BasicNameValuePair("password", password.getText().toString()));
String un = userid.getText().toString();
String pass = password.getText().toString();
System.out.println("user name is " + un);
System.out.println("password is " +pass);
// Log.e(""+sid.getText().toString(),"0");
// Log.e(""+sname.getText().toString(),"0");
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://mywebsite.com/login.php");
httppost.setEntity(new UrlEncodedFormEntity(nvp));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch(Exception e){
Log.e("log_tag", "Error in http connection"+e.toString());
}
try {
BufferedReader bf = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
sb = new StringBuilder();
sb.append(bf.readLine()+ "\n");
String line="0";
while ((line = bf.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
System.out.println("value of result " +result);
if(result.contains(auth)){
System.out.println("username and password is correct");
Intent authorised = new Intent(Login.this,BrowseFiles.class);
startActivity(authorised);
}else{
System.out.println("incorrect wrong wrong wrong");
error.setText("Incorrect username and password");
}
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
答案 0 :(得分:1)
您可以将[{3}}用于您的应用程序,并在开始下载时进行检查。如果已设置,则可以继续打开登录/注册页面,无论您想要什么
编辑:
用户成功登录后
SharedPreferences share_pref=PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = share_pref.edit();
editor.putBoolean("Login", true);
// Commit the edits!
editor.commit();
然后在下载之前你可以检查这个布尔值,如果它是真的那么下载别的去登录屏幕