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