0
我正在使用android 2.2的家伙。我有一种情况,当用户进入应用程序时,他将允许使用提供的默认音频文件。注册用户只能被认证一次
现在有一个按钮,当他点击它将进入登录页面。如果他不是注册用户,他可以注册自己,并再次用用户名和密码登录。一旦他用他的用户名和密码登录,他会被允许从服务器下载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());
}
我需要存储用户名和密码?你可以请给我任何例子在这 – Goofy 2012-03-07 05:35:57
参考链接它将显示一个例子也使用sharedPreference并显示如何编辑也 – 2012-03-07 05:41:58
你只需要编辑时,用户通过身份验证,并检查它下载按钮按下之前的内容.. .. – 2012-03-07 05:44:20