guys i am working on android 2.2.I have a situation where when the user enters the application he will allowed to use the default audio file provided.
Now there is a button when he clicks on it will go to login page.If he is not a registered user he can register himself and again login with the username and password.Once he logins with his username and password he will be allowed to download n number of audio files from the server.
So what i want to acheive is once the user is a registered user and logins and exits the application but again if the registered user wants to download some more files he should not be prompted with username and password since he is a registered user.
How to acheive this?
Code to login the registered user:
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());
}
You can use the SharedPreference for your application and check it when you starts downloading .if it is setted then you can continue otherwise open Login/registartion page whatever you want
EDIT:
Once user is successfully login
then before downloading you can check this boolean value if it is true then do downloading else go to login screen